必须声明标量变量" @电子邮件和QUOT; [英] Must declare the scalar variable "@Email"
问题描述
我试图从数据库表值传递给一对夫妇的标签,其中电子邮件列中的电子邮件entered.I匹配已通过电子邮件使用session.Like从登录页面进入到这个页面。这:
I am trying to pass values from a database table to a couple of labels where the email column matches the email entered.I have passed the email entered from login page to this page using a session.Like This :
protected void btnLogin_Click(object sender, EventArgs e)
{
if (AuthenticateUser(txtEmail.Text, txtPassword.Text))
{
FormsAuthentication.RedirectFromLoginPage(txtEmail.Text, chkBoxRememberMe.Checked);
Session["Email"] = txtEmail.Text;
Response.Redirect("~/Account.aspx");
}
那么,我该会话值传递给lblEmail上ACOUNTS page.and然后我试图检索值名称,并从数据库TABEL'平衡',其中电子邮件匹配一个在table.Like本:
then i am passing the session value to lblEmail on ACOUNTS page.and then i am trying to retrieve values 'Name' and 'Balance' from database tabel where Emails match the one in the table.Like This:
protected void Page_Load(object sender, EventArgs e)
{
lblEmail.Text = Session["Email"].ToString();
string CS = ConfigurationManager.ConnectionStrings["ABCD"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("Select * from tblRegister where @Email = " + lblEmail.Text, con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
rdr.Read();
lblName.Text = rdr["Name"].ToString();
lblBalance.Text = rdr["Balance"].ToString();
}
但我得到一个错误消息,指出必须声明标量vraiable @Email下面的一行:
But i get a error message stating 'must declare the scalar vraiable @Email' on the line below:
SqlDataReader rdr = cmd.ExecuteReader();
我究竟做错了什么?
What am i doing wrong?
推荐答案
尝试这样的而不是
SqlCommand cmd = new SqlCommand("Select * from tblRegister where Email = @Email", con);
cmd.Parameters.AddWithValue("@Email", lblEmail.Text);
SqlDataReader rdr = cmd.ExecuteReader();
//...
这篇关于必须声明标量变量" @电子邮件和QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!