I need to insert data when user clicks. But, my code isn't doing it. Even though it displays the data inserted message, the data is not inserted. How can I find the mistake?
private void bunifuFlatButton2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=**F:\Blackhat\Blackhat\Blackhat.mdf**;Integrated Security=True");
try
{
con.Open();
SqlCommand cmd = new SqlCommand("Insert Into Clients(name) VALUES ('"+clientname.Text+"')", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Success "+clientname.Text);
con.Close();
}
catch (SqlException ex)
{
MessageBox.Show("Failed"+ex);
}
}