我遇到了datatableadapter.update(dataset)的问题。一切正常,直到我向数据库添加一个新列,它将显示新项目但是当我尝试通过dataviewgrid更新值时。我没有错误,但数据没有保存。这是代码。
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Record Updated");
this.inventoryTableAdapter.Update(jobDetailsDataSet.Inventory);
}
private void button1_Click(object sender, EventArgs e)
{
this.inventoryTableAdapter.Fill(this.jobDetailsDataSet.Inventory);
}
private void btnadd_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(global::FarWest_Program.Properties.Settings.Default.JobDetailsConnectionString);
try
{
string sql;
sql = "ALTER TABLE Inventory ADD " + txtitem.Text + " VARCHAR (50)";
this.inventoryTableAdapter.Fill(this.jobDetailsDataSet.Inventory);
SqlCommand execommand = new SqlCommand(sql, cn);
cn.Open();
execommand.ExecuteNonQuery();
MessageBox.Show("You have Updated The Job Details", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + Environment.NewLine + "Please Check to See you only used Numbers", "Only Numbers Allowed", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
cn.Close();
}
}