如何从输入框中获取数据并使用数据集将其插入数据库?
这就是我现在在数据服务类中所拥有的:
public void Update(DataTable dt)
{
try
{
da = new OleDbDataAdapter("Select * from [" + dt.TableName + "]", cn);
cn.Open();
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
cb.QuotePrefix = "[";
cb.QuoteSuffix = "]";
da.Update(dt);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
cn.Close();
}
}
这是按钮点击
private void btnInsert_Click(object sender, EventArgs e)
{
try
{
//dc = DataService Class
//ds = DataSet From DataService Class
dc.Update(ds.Tables["Customers"]);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
是否可以在 da.Update 上插入?当您在 DataGridView 中编辑然后单击它插入的 btninsert 时,这可以正常工作。我将如何从文本框中获取输入并将其插入数据库?