yuanyuanfighting 2017-05-21 05:39 采纳率: 100%
浏览 1252
已采纳

急急急C#中数据库查询报错

 public bool ValidateUser(string userType, string userId, string pwd, ref string message)
        {
            int count = 0;//数据库查询的结果
            bool isValidateUser = false;//返回值,是否找到该用户

            //查询数据库中是否存在与登录时输入的用户名密码用户类型匹配的信息
           string sql = "select count(*) from user where userId='"+userId+"' and userType='"+userType+"' and pwd='"+pwd+"'";
            //string sql = string.Format("select COUNT(*) from dbo.user where userId=admin AND userType=管理员 AND pwd=123456");
            try
            {
                conn.connection.Open();
                SqlCommand command = new SqlCommand(sql, conn.connection);
                count=(int)command.ExecuteScalar();
                if (count == 1)
                {
                    isValidateUser = true;
                }

报错‘user’附近有语法错误,我看了很多遍也没看出错误在哪,麻烦大虾们帮帮忙

  • 写回答

2条回答 默认 最新

  • Go 旅城通票 2017-05-21 05:57
    关注

    改这样试试

      string sql ="select count(*) from [user] where [userId]='"+userId+"' and [userType]='"+userType+"' and [pwd]='"+pwd+"'";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大