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条回答 默认 最新

  • 斯洛文尼亚旅游 2017-05-21 05:57
    关注

    改这样试试

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

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失