数据读取器未读取数据 [英] Datareader is not reading the data
本文介绍了数据读取器未读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
如果用户类型为"admin",则数据读取器不会从表中读取值...
有人可以帮我吗?
这是我的代码:
Hi everyone,
If usertype is "admin" the datareader is not reading values from the table...
Can anybody help me with this??
Here is my code :
String username = TextBox1.Text.ToString();
String password = TextBox2.Text.ToString();
String utype = DropDownList1.Text.ToString();
if (utype == "user")
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["WATERMARKING"].ToString());
String query = "Select USERNAME,PASSWORD,UTYPE from PROFILE where USERNAME=''" + username + "'' and PASSWORD = ''" + password + "'' and UTYPE= ''" + utype + "'' ";
SqlCommand cmd = new SqlCommand(query, cn);
cn.Open();
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
reader.Read();
if (reader.HasRows)
{
HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.Redirect(Session["URL"].ToString());
}
else
{
HttpContext.Current.ApplicationInstance.CompleteRequest();
//Response.Redirect( "LOGIN.aspx" ) ;
String s = "invalid user password or username";
Response.Write(s);
}
}
else if(utype=="admin")
{
SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["WATERMARKING"].ToString());
String queryy = "Select USERNAME,PASSWORD from PROFILE where USERNAME=''" + username + "'' and PASSWORD = ''" + password + "'' ";
SqlCommand cmd = new SqlCommand(queryy, cnn);
cnn.Open();
SqlDataReader readerr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
readerr.Read();
if (readerr.HasRows)
{
HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.Redirect(Session["URLL"].ToString());
//Response.Write("helo");
}
else
{
//HttpContext.Current.ApplicationInstance.CompleteRequest();
//Response.Redirect( "LOGIN.aspx" ) ;
String s = "invalid admin password or username";
Response.Write(s);
}
}
推荐答案
您确定DropDownList1的值更改为"admin"吗?希望您已将调试器&确认值已更改为admin&实际的问题出在Reader.Also,您的查询中,我没有看到utype被传递给admin.这不是必需的吗?
Are you sure that DropDownList1 value is changing to "admin" ?I hope you have put debugger & confirmed that value is getting changed to admin & the actual problem is with reader.Also,your query,I dont see utype being passed for admin.Is that not required for this?
String queryy = "Select USERNAME,PASSWORD from PROFILE where USERNAME=''" + username + "'' and PASSWORD = ''" + password + "'' ";
这篇关于数据读取器未读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文