i am trying to insert into database, The problem is insertion data not save in my DataBase1.mdf i dont know why?
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(); }