急求各路大神搭救啊!!!!!!

zeng0915 zeng0915 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
应老师要求做一个信息管理的简单web系统,但在链接数据库的时候出现了这样的问题,,由于道行不够,怎么都解决不了。
问题如下:
我用了一个login控件,
获取两个文本框的值,
以下是我用来测试链接的,获取数据库中的值,设了断点,看读取的是什么值
//获取用户名控件
TextBox txtUserName = (TextBox)Login1.FindControl("UserName");
string userName = txtUserName.Text.Trim();

//获取密码控件
TextBox txtPsw = (TextBox)Login1.FindControl("Password");
string psw = txtPsw.Text;

//错误显示控件

//查询语句
string sql = "select * from DL where uId=@userName and passWord=@passWord";

//为参数赋值
SqlParameter[] pms = new SqlParameter[] { new SqlParameter("@userName", userName), new SqlParameter("@password", psw) };
string constr = "Data Source=GG;Initial Catalog=LianXiDB;User ID=sa;Password=123";
//判断用户名与密码是否正确
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand scd = new SqlCommand(sql,con))
{
scd.Parameters.AddRange(pms);
con.Open();
using (SqlDataReader read = scd.ExecuteReader())
{
if (read.HasRows)
{

string id = read.GetString(0);
string psww = read.GetString(1);


}
}
}
}

结果就成这样子了

请大哥们指点一下迷津,小弟不胜感激!!谢谢
...全文

相关推荐

评论 9
收藏 已收藏
分享
返回顶部
zeng0915
.NET社区 62,272 成员 668,968 内容