提示INSERT INTO 语句的语法错误。 报错语句 int i = cmd.ExecuteNonQuery();
报错语句inti=cmd.ExecuteNonQuery();添加代码:OleDbConnectionobjConnection=newOleDbConnection(s...
报错语句 int i = cmd.ExecuteNonQuery();
添加代码: OleDbConnection objConnection = new OleDbConnection(strConnection);
objConnection.Open();
string insert_sql = "insert into login_admin values(@username,@password)";
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = insert_sql;
cmd.Connection = objConnection;
cmd.Parameters.Add("@username", OleDbType.VarChar).Value = txtusername.Text;
cmd.Parameters.Add("@password", OleDbType.VarChar).Value = txtpassword.Text;
int i = cmd.ExecuteNonQuery();
if (i > 0) { MessageBox.Show("注册信息成功!"); }
else {MessageBox.Show("注册信息失败!"); }
objConnection.Close();
添加语句改了还是报错string insert_sql = "insert into login_user (username,password) values(@username,@password)";提示INSERT INTO 语句的语法错误。 报错语句 int i = cmd.ExecuteNonQuery(); 展开
添加代码: OleDbConnection objConnection = new OleDbConnection(strConnection);
objConnection.Open();
string insert_sql = "insert into login_admin values(@username,@password)";
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = insert_sql;
cmd.Connection = objConnection;
cmd.Parameters.Add("@username", OleDbType.VarChar).Value = txtusername.Text;
cmd.Parameters.Add("@password", OleDbType.VarChar).Value = txtpassword.Text;
int i = cmd.ExecuteNonQuery();
if (i > 0) { MessageBox.Show("注册信息成功!"); }
else {MessageBox.Show("注册信息失败!"); }
objConnection.Close();
添加语句改了还是报错string insert_sql = "insert into login_user (username,password) values(@username,@password)";提示INSERT INTO 语句的语法错误。 报错语句 int i = cmd.ExecuteNonQuery(); 展开
2个回答
展开全部
public static User AddUser(User user)
{
string sql =
"INSERT Users (LoginId, LoginPwd, Name, Address, Phone, Mail, UserRoleId, UserStateId)" +
"VALUES (@LoginId, @LoginPwd, @Name, @Address, @Phone, @Mail, @UserRoleId, @UserStateId)";
sql += " ; SELECT @@IDENTITY";
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@UserStateId", user.UserState.Id), //FK
new SqlParameter("@UserRoleId", user.UserRole.Id), //FK
new SqlParameter("@LoginId", user.LoginId),
new SqlParameter("@LoginPwd", user.LoginPwd),
new SqlParameter("@Name", user.Name),
new SqlParameter("@Address", user.Address),
new SqlParameter("@Phone", user.Phone),
new SqlParameter("@Mail", user.Mail)
};
int newId = DBHelper.GetScalar(sql, para);
return GetUserById(newId);
}
{
string sql =
"INSERT Users (LoginId, LoginPwd, Name, Address, Phone, Mail, UserRoleId, UserStateId)" +
"VALUES (@LoginId, @LoginPwd, @Name, @Address, @Phone, @Mail, @UserRoleId, @UserStateId)";
sql += " ; SELECT @@IDENTITY";
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@UserStateId", user.UserState.Id), //FK
new SqlParameter("@UserRoleId", user.UserRole.Id), //FK
new SqlParameter("@LoginId", user.LoginId),
new SqlParameter("@LoginPwd", user.LoginPwd),
new SqlParameter("@Name", user.Name),
new SqlParameter("@Address", user.Address),
new SqlParameter("@Phone", user.Phone),
new SqlParameter("@Mail", user.Mail)
};
int newId = DBHelper.GetScalar(sql, para);
return GetUserById(newId);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询