简体   繁体   English

值未从文本框传递到代码

[英]Values not passed from Textbox to code

my code : 我的代码:

region check what Login button do 区域检查“登录”按钮的作用

    private void btnLogin_Click(object sender, EventArgs e)
    {
        if (this.txtUserName.Text == "" || this.txtPassword.Text == "")
        {
            MessageBox.Show("Credentials are missing...", clsVariables._strProjectName, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        else
        {
            string _strQuery = "SELECT AtNumConstructorID, TxtConstructorName AS Fullname, tblConstructorDetails.txtUserName FROM tblConstructorDetails WHERE txtUserName = '" + this.txtUserName.Text + "' AND TxtPassword LIKE '" + this.txtPassword.Text + "' ";
            if (clsFunctions.recordExist(_strQuery, "tblConstructorDetails") == true)
            {
                clsVariables._sTimeLogin = DateTime.Now.ToLongTimeString();//recording the time of login in the CES
                long totalRow = 0;
                //Set the Data Adapter
                OleDbDataAdapter da = new OleDbDataAdapter(_strQuery, clsConnections._olbedbCN);
                DataSet ds = new DataSet(); // creating a dataset to enter the values in the dataadapter
                da.Fill(ds, "tblConstructorDetails");
                totalRow = ds.Tables["tblConstructorDetails"].Rows.Count - 1;
                clsVariables._sContId = Convert.ToInt32(ds.Tables["tblConstructorDetails"].Rows[0].ItemArray.GetValue(0));
                clsVariables._sConstructor = ds.Tables["tblConstructorDetails"].Rows[0].ItemArray.GetValue(1).ToString();
                clsVariables._sUserID = ds.Tables["tblConstructorDetails"].Rows[0].ItemArray.GetValue(2).ToString();
                clsUserLogs.RecordLogin(clsVariables._sTimeLogin, clsVariables._sContId);
                clsApplication._boolAPP_CONNECTED = true;
                this.Close();

            }
            #region trash code 2
            /*string _strUsername = this.txtUserName.Text.Trim();
            string _strPassword = txtPassword.Text;
            string _strSQL = "select * from tblConstructorDetails where Upper(TxtUserName) = '" +  _strUsername.ToUpper() +"' and TxtPassword = '" + _strPassword +  "'";
            if ()
            {

            } */
            #endregion

            else
            {
                clsVariables._intAttempt--;
                if (clsVariables._intAttempt > 0)
                {
                    MessageBox.Show("Login failed. Please try again. Only " + Convert.ToString(clsVariables._intAttempt) + " attempts remaining...", "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Exiting the system", clsVariables._strProjectName, MessageBoxButtons.OK);
                    this.Close();
                }
            }
        }
    }
    #endregion

code for recordExist : recordExist的代码:

    #region Filters the records if exists in the table
    //Filter if Recort is Exist in the Table.
    public static bool recordExist(string _sSQL, string _sTable)
    {
        long totalRow = 0;
        //Set the Data Adapter
        OleDbDataAdapter _oledbAdDa = new OleDbDataAdapter(_sSQL, _olbedbCN);
        DataSet _ds = new DataSet();
        _oledbAdDa.Fill(_ds, _sTable);
        totalRow = Convert.ToInt32(_ds.Tables[_sTable].Rows.Count);
        if (totalRow > 0) { return true; }
        else { return false; }
    }
    #endregion

The problem I am facing is that, when I try to enter values in the corresponding textbox, that values are not been passed to the query for checking if the login is available or not.... 我面临的问题是,当我尝试在相应的文本框中输入值时,该值未传递给查询以检查登录名是否可用。

Please check the same and provide me the possible solution and reason for why this thing is happening.... 请进行相同的检查,并向我提供可能的解决方案以及发生这种情况的原因。

Thanx in advance.... 提前感谢...

you probably want to change the string comparison operator in your sql from 您可能想从以下位置更改sql中的字符串比较运算符

= =

to

LIKE 喜欢

I get the feeling that you have miss asked your question and really the problem is the sql returning no data. 我感觉到您错过了问您的问题,实际上问题是sql不返回任何数据。

string _strQuery = "SELECT AtNumConstructorID, TxtConstructorName AS Fullname, tblConstructorDetails.txtUserName FROM tblConstructorDetails WHERE txtUserName LIKE '" 
+ this.txtUserName.Text + "' AND TxtPassword LIKE '" + this.txtPassword.Text + "' "; 

the change is right at the ernd of the first line. 更改恰好位于第一行的中间。

http://xkcd.com/327/ http://xkcd.com/327/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM