编程论坛's Archiver

andriysmith 发表于 2008-5-27 18:27

如何实现用ID号登录,登录后显示用户名?

请问哪位高手可以教一教我.....急用!
SqlCommand scd = new SqlCommand("select count(*) from SysUser where U_ID='" + this.UID.Text.ToString() + "' and U_PSW='" + this.Userpwd.Text.ToString() + "'", sqlcon);
        int count = Convert.ToInt32(scd.ExecuteScalar());
        if (count > 0)
        {
            Session["U_ID"] = this.UID.Text.ToString();
            this.Panel2.Visible = true;
            this.Panel1.Visible = false;
            this.Label1.Text = Session["U_ID"].ToString();
        }
        else
        {
            Response.Write(this.message("编号或者密码错误"));
        }

hebingbing 发表于 2008-5-27 21:06

上面的程序不是可以完成你要的功能吗?

petroe 发表于 2008-5-27 22:22

SqlCommand scd = new SqlCommand("select count(*) from SysUser where U_ID='" + this.UID.Text.ToString() + "' and U_PSW='" + this.Userpwd.Text.ToString() + "'", sqlcon);

数据库查询语言写错了,你的那种是返回记录总数
应该这样写,
SqlCommand scd = new SqlCommand("select * from SysUser where U_ID='" + this.UID.Text.ToString() + "' and U_PSW='" + this.Userpwd.Text.ToString() + "'", sqlcon);

然后用 datereader 读出来。建议LZ多看点基础。

andriysmith 发表于 2008-5-27 23:27

这是显示ID号,不显示用户名

cyyu_ryh 发表于 2008-5-28 10:34

有没用户名这个字段哦?

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.