错误:SqlDataReader DataReader [英] Error: SqlDataReader DataReader
本文介绍了错误:SqlDataReader DataReader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人能告诉我为什么我在代码的最后一行收到此错误吗?
必须声明标量变量@userpassword。
Hi,
Can someone tell me why i am getting this error for the last line in the code?
Must declare the scalar variable "@userpassword".
Line 27: SqlDataReader DataReader = command.ExecuteReader();
if (Page.IsValid)
{
SqlConnection con = new SqlConnection("Data Source=MZC-RWAHDAN\\MYPROJECT2015;Persist Security Info=True;User ID=sa; Password=Fatima2010;Initial Catalog=Testing_database");
SqlCommand command = new SqlCommand("SELECT * FROM users_login WHERE username = @username AND userpassword = @userpassword", con);
con.Open();
command.Parameters.AddWithValue("@Username", TextBox1.Text);
command.Parameters.AddWithValue("@Password", TextBox2.Text);
SqlDataReader DataReader = command.ExecuteReader();
推荐答案
替换
Replace
command.Parameters.AddWithValue("@Password", TextBox2.Text);
with:
with:
command.Parameters.AddWithValue("@userpassword", TextBox2.Text);
查询中参数的名称必须匹配AddWithValue方法中参数的名称。
The name of the parameter in the query must match the name of the parameter in the AddWithValue method.
这篇关于错误:SqlDataReader DataReader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文