MY新 2013-07-29 18:17 采纳率: 25%
浏览 2014

他说 = 附近有语法错误 找来找去不知道=有什么错误

//登录事件处理方法
private void button1_Click(object sender, EventArgs e)
{
try
{

            string sql = string.Format("select uname,password,userrole from tb_userinfo where uname={0}", this.tb_name.Text.Trim());
            DataSet ds = sqlHple.GetDateSet(sql);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                //判断当前用户登录进来的密码是否与传进来的密码相等
                if (ds.Tables[0].Rows[0]["uname"].ToString().Equals(this.tb_pwd.Text.Trim()))
                {
                    //对用户名和用户角色进行赋值
                    Program.username = ds.Tables[0].Rows[0]["uname"].ToString();
                    Program.userrole = ds.Tables[0].Rows[0]["userrole"].ToString();
                    //是否显示主窗体
                    Program.isshowmina = true;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("用户密码输入错误");
                }

            }
            else
            {
                MessageBox.Show("用户名输入错误");
                return;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}

}
这个是sqlHple.GetDateSet里面的方法
public static DataSet GetDateSet(string sql)
{

        SqlConnection con = new SqlConnection(strcon);
        DataSet ds = new DataSet();
        SqlDataAdapter sda = new SqlDataAdapter(strcon, con);
        sda.Fill(ds);
        return ds;

    }
  • 写回答

1条回答 默认 最新

  • u010618015 2013-07-30 01:53
    关注

    select uname,password,userrole from tb_userinfo where uname={0}中的uname是字符类型应该加单引号 uname='{0}'

    评论

报告相同问题?

悬赏问题

  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊