C# winform中语法错误 (操作符丢失) 在查询表达式 ''' ''' 中。 20
代码如下:stringsql="select*fromUserswhereID="+id+"";OleDbCommandsqlcmd=newOleDbCommand(sq...
代码如下:
string sql = "select * from Users where ID=" + id + "";
OleDbCommand sqlcmd = new OleDbCommand(sql, DB.getconn());
if (sqlcmd.ExecuteScalar() == null)
{
string sql1 = "insert into Users(ID,username,userpassword,type,anothername,remarks,suspend)values(" + id + ",'" + username + "','" + userpassword + "','" + type + "','" + anothername + "' '" + remarks + "','启用')";
OleDbCommand sqlcmd1 = new OleDbCommand(sql1, DB.getconn());
if (sqlcmd1.ExecuteNonQuery() < 1)
{
MessageBox.Show("添加用户失败!");
return;
}
else
{
MessageBox.Show("添加用户成功!");
}
}
if (sqlcmd1.ExecuteNonQuery() < 1 )错误提示这一行 展开
string sql = "select * from Users where ID=" + id + "";
OleDbCommand sqlcmd = new OleDbCommand(sql, DB.getconn());
if (sqlcmd.ExecuteScalar() == null)
{
string sql1 = "insert into Users(ID,username,userpassword,type,anothername,remarks,suspend)values(" + id + ",'" + username + "','" + userpassword + "','" + type + "','" + anothername + "' '" + remarks + "','启用')";
OleDbCommand sqlcmd1 = new OleDbCommand(sql1, DB.getconn());
if (sqlcmd1.ExecuteNonQuery() < 1)
{
MessageBox.Show("添加用户失败!");
return;
}
else
{
MessageBox.Show("添加用户成功!");
}
}
if (sqlcmd1.ExecuteNonQuery() < 1 )错误提示这一行 展开
1个回答
展开全部
string sql = "select * from Users where ID=" + id + ""; 错了
用这个 少了个’
string sql = "select * from Users where ID='" + id + "";
string sql1 = "insert into Users(ID,username,userpassword,type,anothername,remarks,suspend)values(" + id + ",'" + username + "','" + userpassword + "','" + type + "','" + anothername + "' '" + remarks + "','启用')";
这里也错了 少'
string sql1 = "insert into Users(ID,username,userpassword,type,anothername,remarks,suspend)values('" + id + ",'" + username + "','" + userpassword + "','" + type + "','" + anothername + "','" + remarks + "','启用')";
用这个 少了个’
string sql = "select * from Users where ID='" + id + "";
string sql1 = "insert into Users(ID,username,userpassword,type,anothername,remarks,suspend)values(" + id + ",'" + username + "','" + userpassword + "','" + type + "','" + anothername + "' '" + remarks + "','启用')";
这里也错了 少'
string sql1 = "insert into Users(ID,username,userpassword,type,anothername,remarks,suspend)values('" + id + ",'" + username + "','" + userpassword + "','" + type + "','" + anothername + "','" + remarks + "','启用')";
更多追问追答
追问
改成了这样就提示:标准表达式中数据类型不匹配。
追答
' 这个符号得是英文状态下,估计我打的时候是中文的,你现在再试试。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询