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 APosted Jun 23, 2017, 8:08 AM
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.