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}'

    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办