我认为错误可能来自我可能正在使用的保留字,但我不知道哪个字。上次我遇到这个问题是在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");
我将默认值放入行中,并检查以确保数据类型匹配。我最初没有包含字段名称,而是第一次使用字段索引。
答案 0 :(得分:1)
dRow [“C o_Citizenship”]在C和o之间是否有空格?
答案 1 :(得分:0)
我会将它包装在try / catch中,看看它特别窒息
try
{
clientAD.Update(clientDS, "Client");
}
catch( Exception oError )
{
MessageBox.Show( oError.Message );
}
但是如果你在实际的MessageBox上放置一个断点并在watch调试窗口(或局部变量调试窗口)中查看整个oError对象,它可能会为你公开一些更具体的细节。就我们所知,您可能会尝试在具有自动增量列的表上发出“更新”,该列是专门为只读的,不会让您触摸它。如果您尝试设置ID,可能会考虑更改的值并尝试强制通过。
另外,您引用的是“clientAD”,它是OleDbDataAdapter的一个实例。您可能必须指定作为基础的主键“列”。