SqlConnection con = new SqlConnection(); con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\db.mdf;Integrated Security=True;User Instance=True"; SqlCommand cmd = new SqlCommand(); cmd.CommandText = "insert into t1 (name,age) values (@name,@age)"; cmd.CommandType = CommandType.Text; cmd.Connection = con; SqlParameter name_param = new SqlParameter("@name", SqlDbType.VarChar, 50); name_param.Value = textBox1.Text; cmd.Parameters.Add(name_param); SqlParameter age_param = new SqlParameter("@age", SqlDbType.VarChar, 10); age_param.Value = textBox2.Text; cmd.Parameters.Add(age_param); con.Open(); int result = cmd.ExecuteNonQuery(); if (result != 0) { lb1.Visible = true; lb1.Text = "added"; } else { lb1.Visible = true; lb1.Text = "error"; } con.Close();