用access添加一条记录
public static bool AddUser(User user)
{
string OleDb = "INSERT INTO [User]([UserName],[UserLoginID], [UserLoginPassword],[Sex],[Organization],[Address],[Telphone],[Electricaltransmission],[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;
}
}
查询值的数目与目标字段中的数目不同。
string OleDb = "INSERT INTO [User]([UserName],[UserLoginID], [UserLoginPassword],[Sex],[Organization],[Address],[Telphone],[Electricaltransmission],[Email],[Business],[Photo]) VALUES('UserName','UserLoginID','UserLoginPassword','Sex','Organization','Address','Telphone','Email','Business','Photo')";
少些一个参数吧.