如何從DataGridView C#更新數據庫?我的項目是在DB.but負載數據表工作不能更新到數據庫 它的負載數據按鈕如何從DataGridView更新數據庫C#
private void button2_Click(object sender, EventArgs e)
{
string connectionString;
connectionString = "Server=localhost;User Id=root; Password=1234; Database=db2; Pooling=false;CharSet=tis620;";
connection = new MySqlConnection(connectionString);
sda = new MySqlDataAdapter("Select * from data Where Id = '" + comp.Text.Trim() + "'", connection);
dt = new DataTable();
sda.Fill(dt);
Table1.DataSource = dt;
}
和更新按鈕
private void button3_Click(object sender, EventArgs e)
{
cmdbl = new MySqlCommandBuilder(sda);
sda.Update(dt);
MessageBox.Show("Save data complete");
}
我按照這個片段Insert,Delete and Update data in database from datagridview ,我可以」 t do it 對不起,我的英語說得不夠好,謝謝你的回答。
嘗試dt.AcceptChanges()後更新 – Srikanth