When my program is running, the first time that I insert data, they show in gridView1 but not store in database1.mdf
anyone help me
DB name : inventry
table name: addProduct
column : pid,title,descrtion,type,vendor,price,isbn
full project is attached
Button code file
private void button1_Click(object sender, EventArgs e) { String con = ConfigurationManager.ConnectionStrings["inven"].ConnectionString; SqlConnection connection = new SqlConnection(con); connection.Open(); SqlCommand cmd = new SqlCommand("Insert into addProduct(title,descrtion,type,vendor,price,isbn) values(@title,@descrtion,@type,@vendor,@price,@isbn)", connection); cmd.Parameters.AddWithValue("@title", textBox1.Text); cmd.Parameters.AddWithValue("@descrtion", textBox2.Text); cmd.Parameters.AddWithValue("@type", textBox3.Text); cmd.Parameters.AddWithValue("@vendor", textBox4.Text); cmd.Parameters.AddWithValue("@price", textBox5.Text); cmd.Parameters.AddWithValue("@isbn", textBox6.Text); int rows = cmd.ExecuteNonQuery(); if (rows != 0) { MessageBox.Show("Inserted"); } else { MessageBox.Show("Insertion failure"); } connection.Close(); }
Ahmed JSPosted Nov 19, 2014, 10:03 AM
http://sqlneed.blogspot.com/2014/06/passing-parameter-in-c-to-sql-stored.html
raajaa khanPosted Nov 3, 2014, 8:01 AM
Rajagopalan R VPosted Nov 3, 2014, 6:07 AM
From Above question and From Your Code i found that You Had Created database separately and inserting Values into Separate table Not on the Your DataBase1.mdf, so that is the problem Create a New Table inside Your Database Store inside on that
Refer the Below Link
http://mrbool.com/inserting-data-into-sql-server-database-using-csharp-and-asp-net/25091
It Will be Useful to You
If You Clear With this Solution Please Kindly Mark it as Answer
Thanks & Regards....,
Rajagopalan R.V