string OleDb = "INSERT INTO [User]([UserName],[UserLoginID],[UserLoginPassword],[Sex],[Organization],[Address],[Telphone],[Email],[Business],[Photo]) VALUES('@UserName','@UserLoginID','@UserLoginPassword','@Sex','@Organization','@Address','@Telphone','@Email','@Business','@Photo')";
try
{
OleDbParameter[] para = new OleDbParameter[]
{
new OleDbParameter("@UserName",user.UserName),
new OleDbParameter("@UserLoginID",user.UserLoginID),
new OleDbParameter("@UserLoginPassword",user.UserLoginPassword),
new OleDbParameter("@Sex",user.Sex),
new OleDbParameter("@Organization",user.Organization),
new OleDbParameter("@Address",user.Address),
new OleDbParameter("@Telphone",user.Telphone),
new OleDbParameter("@Email",user.Email),
new OleDbParameter("@Business",user.Business),
new OleDbParameter("@Photo",user.Photo),
};
int i=DBHelper.ExecuteCommand(OleDb, para);
return i == 1 ? true : false;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
System.Data.OleDb.OleDbException: 查询值的数目与目标字段中的数目不同。
string OleDb = "INSERT INTO [User]([UserName],[UserLoginID],[UserLoginPassword],[Sex],[Organization],[Address],[Telphone],[Email],[Business],[Photo]) VALUES(''@UserName'',''@UserLoginID'',''@UserLoginPassword'',''@Sex'',''@Organization'',''@Address'',''@Telphone'',''@Email'',''@Business'',''@Photo'')";
//即将所有的单引号替换为两个单引号
表面上看少了photo,代码不完整,看不出来啊。
我看了一下,是不是楼主写参数数组的时候多了一个逗号呀, try
{
OleDbParameter[] para = new OleDbParameter[]
{
new OleDbParameter("@UserName",user.UserName),
new OleDbParameter("@UserLoginID",user.UserLoginID),
new OleDbParameter("@UserLoginPassword",user.UserLoginPassword),
new OleDbParameter("@Sex",user.Sex),
new OleDbParameter("@Organization",user.Organization),
new OleDbParameter("@Address",user.Address),
new OleDbParameter("@Telphone",user.Telphone),
new OleDbParameter("@Email",user.Email),
new OleDbParameter("@Business",user.Business),
new OleDbParameter("@Photo",user.Photo),
};
就是最后那个参数new OleDbParameter("@Photo",user.Photo), 那个后面应该是多余的吧,