private void button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("data source=SAMIRAN-PC; Initial catalog = DB2; Integrated security= true"); SqlDataAdapter dat = new SqlDataAdapter(); dat.InsertCommand = new SqlCommand(" INSERT INTO TAB2 VALUES(@NAME,@AGE)", con); dat.InsertCommand.Parameters.Add("@NAME",SqlDbType.VarChar).Value = textBox1.Text; dat.InsertCommand.Parameters.Add("@AGE", SqlDbType.VarChar).Value = textBox2.Text; con.Open(); dat.InsertCommand.ExecuteNonQuery(); con.Close(); } }
try { // your code here } catch(SqlException ex) { // do something useful with the error Number MessageBox.Show(ex.Number.ToString()); foreach(SqlError s in ex.Errors) { // do something useful with its properties MessageBox.Show(s.ToString()); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)