用我的登录表单声明变量 [英] Declare variable with my login form

查看:95
本文介绍了用我的登录表单声明变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我收到错误,下面的代码我得到的消息是:





Hi
I am getting an error with below code the message that i am getting it is:


Server Error in '/' Application.

Must declare the scalar variable "@uuu". 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@uuu".

Source Error: 



Line 43:                 SqlCommand passcom = new SqlCommand(checkpasswordquery, adminlog);
Line 44:                 cmd.Parameters.AddWithValue("@uuu", adminusernmetxtbx.Text);
Line 45:                 string password = passcom.ExecuteScalar().ToString().Replace(" ", "");
Line 46: 
Line 47: 

< br $> b $ b






protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection adminlog = new SqlConnection(sc);
            adminlog.Open();
            string checkuser = "Select count(*) from UserInfo where UID=@uuu";
            SqlCommand cmd = new SqlCommand(checkuser, adminlog);
            cmd.Parameters.AddWithValue("@uuu",adminusernmetxtbx.Text);
            int temp = Convert.ToInt32(cmd.ExecuteScalar().ToString());


            adminlog.Close();



            if (temp == 1)
            {
                adminlog.Open();
                string checkpasswordquery = "Select count(*) from UserInfo where UID=@uuu";
                SqlCommand passcom = new SqlCommand(checkpasswordquery, adminlog);
                cmd.Parameters.AddWithValue("@uuu", adminusernmetxtbx.Text);
                string password = passcom.ExecuteScalar().ToString().Replace(" ", "");


                if (password == adminpasstxtbx.Text)
                {
                    Session["UsrNme"] = adminusernmetxtbx.Text;
                    Response.Redirect("BeravaAdmin.aspx");
                }

                else
                {
                    adminpasstxtbx.Text = "Password is incorrect";
                }
            }

推荐答案

正如Wes所指出的那样,你声明了第二个名为passcom的SqlCommand对象,但是你将参数添加到cmd对象而不是passcom对象。
As Wes pointed out, you declare a second SqlCommand object named passcom but you then add the parameter to the cmd object not the passcom one.


这篇关于用我的登录表单声明变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆