我正在使用 asqladapter
来直接从 a 更改数据库值datagridview
。
为此,我使用以下代码:
private void ok_Modify_Click(object sender, EventArgs e) {
//modify mod = new modify();
//modify_gv.DataSource = mod.TabletoMod(tickerBox.Text, FundBox.Text);
connetionString = Properties.Settings.Default.TraFra;
connection = new SqlConnection(connetionString);
Sql = "select * from Approval where Ticker ='" + tickerBox.Text + "'";
try {
connection.Open();
adapter = new SqlDataAdapter(Sql, connection);
adapter.Fill(ds);
connection.Close();
modify_gv.DataSource = ds.Tables[0];
} catch (Exception ex) {
MessageBox.Show(ex.ToString());
}
}
private void modify_gv_CellValueChanged(object sender, DataGridViewCellEventArgs e) {
try {
cmdBuilder = new SqlCommandBuilder(adapter);
changes = ds.GetChanges();
if(changes != null)
adapter.Update(changes);
// MessageBox.Show("Changes Done");
} catch (Exception ex) {
MessageBox.Show(ex.ToString());
}
}
但是,每次我在 中进行更改时datagridview
,变量“更改”始终为空。你知道为什么吗?