private void BtnInsert_Click(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection("server=.;database=romesh;integrated security=true");
SqlCommand cmd = new SqlCommand("insert into ObjectMethodChecking values('" + TxtFname.Text + "','" + TxtSurname.Text + "','" + Txtaddress.Text + "'," + TxtPhno.Text + ")", con);
cmd.CommandType = CommandType.Text;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
error will come below my attachment


Abhilash J ARank #1,243 · 1.4K reputationPosted Jun 23, 2017, 4:08 AM EDT
SqlConnectionandSqlCommandareIDisposableObjectMethodCheckingdoesn't exist, then it doesn't exist. I guess you'd correct that by creating it. Also be aware that your code is wide open to SQL injection. You should really be using query parameters for user input, otherwise you're just blindly executing any code your users send you.