UPDATE 语句中的语法错误
我认为错误可能来自我可能正在使用的保留字,但我不知道是哪个字。上次我遇到这个问题是在 INSERT INTO 语句中,我通过在保留字周围加上括号来修复它。但如果是保留字的问题。当代码是这样的时候,如何在保留字两边加上括号?有什么帮助吗?
OleDbCommandBuilder cb;
cb = new OleDbCommandBuilder(clientAD);
DataRow dRow = clientDS.Tables["Client"].Rows[cInc];
bool thingy = false;
int defaultInt = 0;
byte defualtByte = 0;
double defualtDouble = 0.0;
#region dRow items
dRow["ID"] = textBox3.Text;
dRow["ID_Type"] = "";
dRow["LastName"] = textBox1.Text;
dRow["FrstName"] = "";
dRow["MI"] = "";
dRow["MassMail"] = thingy; //Bool
dRow["BusName"] = "";
dRow["Bus"] = thingy; //Bool
dRow["Title"] = "";
dRow["Title2"] = "";
dRow["Sex"] = "";
dRow["Cli_DOB"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["Spo_DOB"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["Salute"] = "";
dRow["Salute2"] = "";
dRow["Spouse"] = "";
dRow["SSAN"] = "";
dRow["Review"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["Occup"] = "";
dRow["AgentNo"] = defaultInt; //Int32
dRow["Status"] = "";
dRow["Wedding_DT"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["Flag_1"] = "";
dRow["Flag_2"] = "";
dRow["Flag_3"] = "";
dRow["Flag_4"] = "";
dRow["Flag_5"] = "";
dRow["Flag_6"] = "";
dRow["Flag_7"] = "";
dRow["Flag_8"] = "";
dRow["Flag_9"] = "";
dRow["Flag_10"] = "";
dRow["Group"] = thingy; //Bool
dRow["GroupMember"] = thingy; //Bool
dRow["KeyWords"] = "";
dRow["Smoker"] = "";
dRow["Married"] = "";
dRow["NumChild"] = defaultInt; //Int32
dRow["NetAsset"] = defaultInt; //Int32
dRow["Income"] = defualtByte; //Byte
dRow["LstUpdate"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["AutoSal"] = "";
dRow["CIP_ID"] = defaultInt; //Int32
dRow["EmailAddr_1"] = "";
dRow["EmailAddr_2"] = "";
dRow["UD1"] = "";
dRow["UD2"] = "";
dRow["UD3"] = "";
dRow["UD4"] = "";
dRow["UD5"] = "";
dRow["UD6"] = "";
dRow["UD7"] = "";
dRow["UD8"] = "";
dRow["UD9"] = "";
dRow["UD10"] = "";
dRow["UD11"] = "";
dRow["UD12"] = "";
dRow["UD13"] = "";
dRow["UD14"] = "";
dRow["UD15"] = defualtDouble; //Double
dRow["UD16"] = defualtDouble; //Double
dRow["UD17"] = defualtDouble; //Double
dRow["UD18"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["UD19"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["UD20"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["New"] = thingy; //Bool
dRow["TDate"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["TTime"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["ImportID"] = defaultInt; //Int32
dRow["SalespTxt"] = "";
dRow["Notepad"] = "";
dRow["ANote"] = "";
dRow["expCount"] = defaultInt; //Int32
dRow["PNote"] = "";
dRow["DrLic_Issue"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["DrLic_Exp"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["DrLic_state"] = "";
dRow["CoDrLic_State"] = "";
dRow["CoDrLic_Issue"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["CoDrLic_Exp"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["Void_check"] = "";
dRow["ASER"] = "";
dRow["Anniversery"] = "";
dRow["Client_Note"] = "";
dRow["C o_Citizenship"] = "";
dRow["Attachment"] = "";
dRow["Pass_Notes"] = "";
dRow["Other_Notes"] = "";
dRow["CE_Notes"] = "";
dRow["Comp_Notes"] = "";
#endregion
clientAD.Update(clientDS, "Client");
我将默认值放入该行中,并检查以确保数据类型匹配。我最初没有包含字段名称,而是第一次使用了字段索引。
I think the error may be coming from a reserved word that I may be using, but I don't know which word. Last time I had this issue was in an INSERT INTO statement and I fixed it by putting brackets around the reserved word. But if it is an issue with a reserved word. How can I put brackets around a reserved word when the code is like this? Any help?
OleDbCommandBuilder cb;
cb = new OleDbCommandBuilder(clientAD);
DataRow dRow = clientDS.Tables["Client"].Rows[cInc];
bool thingy = false;
int defaultInt = 0;
byte defualtByte = 0;
double defualtDouble = 0.0;
#region dRow items
dRow["ID"] = textBox3.Text;
dRow["ID_Type"] = "";
dRow["LastName"] = textBox1.Text;
dRow["FrstName"] = "";
dRow["MI"] = "";
dRow["MassMail"] = thingy; //Bool
dRow["BusName"] = "";
dRow["Bus"] = thingy; //Bool
dRow["Title"] = "";
dRow["Title2"] = "";
dRow["Sex"] = "";
dRow["Cli_DOB"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["Spo_DOB"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["Salute"] = "";
dRow["Salute2"] = "";
dRow["Spouse"] = "";
dRow["SSAN"] = "";
dRow["Review"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["Occup"] = "";
dRow["AgentNo"] = defaultInt; //Int32
dRow["Status"] = "";
dRow["Wedding_DT"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["Flag_1"] = "";
dRow["Flag_2"] = "";
dRow["Flag_3"] = "";
dRow["Flag_4"] = "";
dRow["Flag_5"] = "";
dRow["Flag_6"] = "";
dRow["Flag_7"] = "";
dRow["Flag_8"] = "";
dRow["Flag_9"] = "";
dRow["Flag_10"] = "";
dRow["Group"] = thingy; //Bool
dRow["GroupMember"] = thingy; //Bool
dRow["KeyWords"] = "";
dRow["Smoker"] = "";
dRow["Married"] = "";
dRow["NumChild"] = defaultInt; //Int32
dRow["NetAsset"] = defaultInt; //Int32
dRow["Income"] = defualtByte; //Byte
dRow["LstUpdate"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["AutoSal"] = "";
dRow["CIP_ID"] = defaultInt; //Int32
dRow["EmailAddr_1"] = "";
dRow["EmailAddr_2"] = "";
dRow["UD1"] = "";
dRow["UD2"] = "";
dRow["UD3"] = "";
dRow["UD4"] = "";
dRow["UD5"] = "";
dRow["UD6"] = "";
dRow["UD7"] = "";
dRow["UD8"] = "";
dRow["UD9"] = "";
dRow["UD10"] = "";
dRow["UD11"] = "";
dRow["UD12"] = "";
dRow["UD13"] = "";
dRow["UD14"] = "";
dRow["UD15"] = defualtDouble; //Double
dRow["UD16"] = defualtDouble; //Double
dRow["UD17"] = defualtDouble; //Double
dRow["UD18"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["UD19"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["UD20"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["New"] = thingy; //Bool
dRow["TDate"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["TTime"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["ImportID"] = defaultInt; //Int32
dRow["SalespTxt"] = "";
dRow["Notepad"] = "";
dRow["ANote"] = "";
dRow["expCount"] = defaultInt; //Int32
dRow["PNote"] = "";
dRow["DrLic_Issue"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["DrLic_Exp"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["DrLic_state"] = "";
dRow["CoDrLic_State"] = "";
dRow["CoDrLic_Issue"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["CoDrLic_Exp"] = DateTime.Now.ToShortDateString(); //Date/Time
dRow["Void_check"] = "";
dRow["ASER"] = "";
dRow["Anniversery"] = "";
dRow["Client_Note"] = "";
dRow["C o_Citizenship"] = "";
dRow["Attachment"] = "";
dRow["Pass_Notes"] = "";
dRow["Other_Notes"] = "";
dRow["CE_Notes"] = "";
dRow["Comp_Notes"] = "";
#endregion
clientAD.Update(clientDS, "Client");
I am putting default values into the row, and I've checked to make sure the data types match. And I originally didn't include the field names, I instead used the field indexes the first time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
dRow["C o_Citizenship"] 应该在 C 和 o 之间有一个空格吗?
Should dRow["C o_Citizenship"] have a space between C and o?
我会将其包装在 try/catch 中,看看它具体阻塞了什么
,但是如果您在实际的 MessageBox 上放置断点并在监视调试窗口(或本地变量调试窗口)中查看整个 oError 对象,它可能会暴露一些为您提供更多具体信息。据我们所知,您可能尝试在具有自动增量列的表上发出“更新”,该列是专门只读的并且不允许您触摸它。如果您尝试设置ID,则可能会考虑更改值并尝试强制其通过。
另外,您引用“clientAD”,它是 OleDbDataAdapter 的实例。您可能必须指定作为基础的主键“列”。
I would wrap it in a try/catch and see what its specifically choking on
but if you put a breakpoint on the actual MessageBox and look at the entire oError object in a watch debug window (or local variable debug window), it might expose some more specifics for you. For all we know, you could be trying to issue an "Update" on a table that has an auto-increment column that is specifically read-only and won't let you touch it. If you try to set the ID, it may be considering that a changed value and try to force it through.
Also, you reference your "clientAD" which is an instance of an OleDbDataAdapter. You may have to specify the "column" that is the primary key to be the basis.