public partial class addcustomer : Form {
//query string string q = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|db1.mdf;Integrated Security=True;User Instance=True"; SqlConnection objconnection; public addcustomer() { InitializeComponent(); objconnection = new SqlConnection(q); } private void btnadd_Click(object sender, EventArgs e) { objconnection.Open(); SqlCommand comm = new SqlCommand("insert into customers values(@cid,@cname,@contact,@city)", objconnection); comm.Parameters.AddWithValue("@cid", 10); comm.Parameters.AddWithValue("@cname", txtname.Text.ToString()); comm.Parameters.AddWithValue("@contact", txtcont.Text.ToString()); comm.Parameters.AddWithValue("city", txtcity.Text.ToString()); comm.ExecuteNonQuery(); objconnection.Close(); MessageBox.Show("Record Added"); } }