0
我的代碼有什麼問題。我已經嘗試了另一個代碼,但問題仍然存在。現在我已經解決了這個錯誤幾個星期了,我不知道如何解決它。而且我已經嘗試了一些其他的代碼,但問題仍然是一樣的。C#連接必須有效並且打開Mysql
我想從dataGrid保存多行到我的數據庫。
這裏是我用來保存多行
private void button1_Click(object sender, EventArgs e)
{
MySqlConnection conString = new MySqlConnection("datasource = localhost; port = 3306; Initial catalog = dbnewsystem; username = root;password = 1234");
MySqlCommand command1 = new MySqlCommand("INSERT INTO purchaseorder (orNo, ProdNo, Quantity, total)" +
"VALUES(@ORNo,@ProductNo,@quantity,@total)", conString);
command1.Parameters.AddWithValue("@ORNo", dataGridView1.Rows.Count);
command1.Parameters.AddWithValue("@ProductNo", dataGridView1.Rows.Count);
command1.Parameters.AddWithValue("@quantity", dataGridView1.Rows.Count);
command1.Parameters.AddWithValue("@total", textBox6.Text);
conString.Open();
command1.ExecuteNonQuery();
command1.Connection = conString;
conString.Close();
command1.CommandType = CommandType.StoredProcedure;
command1.CommandText = "pos_save";
if (command1.ExecuteNonQuery() == 1)
{
MessageBox.Show("saved");
}
else
{
MessageBox.Show("Sorry Nothing to be Update");
}
conString.Close();
}
請顯示錯誤消息的完整的堆棧跟蹤。 – OldProgrammer
你可能想刪除conString.Close();在功能的中間,我認爲這是問題所在。 –
@OldProgrammer你是什麼意思的堆棧跟蹤?..對不起,我不是很流利的英文。而且我還在學習編程。 –