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);
}
}
Since there are no exception, the issue would be like, you are writing it to a wrong file in a wrong location or something of that sort.
If it fails to write, there will be an exception and it goes to the catch block.
So we can expect that there are nothing wrong in the c# code.
If you are checking the entries using SQL server management studio, you need try querying the database. The edit 200 rows option needs a database refresh and edit again after closing the existing edit tab. else the vales do not appear to be changing.
Hope this helps. If the issue is something else, please mention in the comments.