void updateTaxPayer()
{
DataRow[] ssnRow = dbSet.Tables["TrackingSheet"].Select("SSN = '" + ssn + "'");
ssnRow[0]["HAS SPOUSE"] = checkboxToString(chkSpouse.CheckState);
ssnRow[0]["SPOUSE SSN"] = txtSpouseSSN.Text;
ssnRow[0]["TNAME"] = txtName.Text;
ssnRow[0]["ADDRESS"] = txtStreetAddress.Text;
ssnRow[0]["CITY"] = txtCity.Text;
ssnRow[0]["STATE"] = cbxState.SelectedIndex.ToString();
ssnRow[0]["ZIP"] = txtZip.Text;
ssnRow[0]["HAS NEW ADDRESS"] = checkboxToString(chkNewAddress.CheckState);
ssnRow[0]["NEW ADDRESS"] = txtNewAddress.Text;
ssnRow[0]["NEW CITY"] = txtNewCity.Text;
ssnRow[0]["NEW STATE"] = cbxNewState.SelectedIndex.ToString();
ssnRow[0]["NEW ZIP"] = txtNewZip.Text;
ssnRow[0]["DATE FILED"] = txtDate.Text;
ssnRow[0]["SSN"] = txtSSN.Text;
dbAdapt.InsertCommand = cmdBuilder.GetInsertCommand(true);
dbAdapt.UpdateCommand = cmdBuilder.GetUpdateCommand(true);
dbAdapt.DeleteCommand = cmdBuilder.GetDeleteCommand(true);
dbAdapt.Update(dbSet,"TrackingSheet");
}
上面是我必须更新我的数据库的代码,但由于某些原因,当我尝试更新时,我得到更新命令的语法错误。我四处搜寻,我不知道该怎么做。
我也尝试过dbAdapt.Update(dbSet,“TrackingSheet”);那也不起作用。
确切的错误是:
System.Data.OleDb.OleDbException (0x80040E14): Syntax error in UPDATE statement.
at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
at trackingform.frmTrackingSheet.updateTaxPayer() in c:\Users\Anthony\Documents\Visual Studio 2012\Projects\trackingform\trackingform\frmTrackingSheet.cs:line 595
at trackingform.frmTrackingSheet.btnSave_Click(Object sender, EventArgs e) in c:\Users\Anthony\Documents\Visual Studio 2012\Projects\trackingform\trackingform\frmTrackingSheet.cs:line 506
第595行:dbAdapt.Update(dbSet,“TrackingSheet”); 第506行:updateTaxPayer();
其他声明:
dbAdapt = new OleDbDataAdapter();
cmdBuilder = new OleDbCommandBuilder(dbAdapt);
dbAdapt.SelectCommand = dbCmd;
dbSet = new DataSet("TrackingSheet");
dbAdapt.Fill(dbSet, "TrackingSheet");
有人有什么想法吗?感谢
答案 0 :(得分:0)
不能肯定地说,但是我怀疑它与你命名列的方式有关 - 使用包含空格的列名,并且在列名的部分之间为解析器创建一些歧义“DATE”和保留字或函数名(如“DATE”函数)。如果您要对语句进行手动编码,则将这些列名称括在引号中,以便SQL解析器能够正确理解它们,但命令构建器可能不会这样做,从而产生无效的SQL。
作为一般做法,我避免在列名中使用空格,并尽量避免使用“保留字”......因为它永远不会确定什么会起作用或不起作用。