它仅检查表中的第一行。帮助某人:) C#winForm

时间:2014-04-26 14:12:31

标签: c#-5.0

SqlConnection con = new SqlConnection(@"Data Source=(local)\SQLEXPRESS; Integrated Security= SSPI;" + "Initial Catalog = CarRent_vaxo;");
con.Open();
string strSQL = "select * from AccesList";
SqlCommand myCommand = new SqlCommand(strSQL, con);
using (SqlDataReader myDataReader = myCommand.ExecuteReader())
{
    myDataReader.Read();
    {
        if (usertextBox.Text == myDataReader["User"].ToString() && paswordTextBox.Text == myDataReader["Password"].ToString())
        {
            this.Hide();
            ResultForm rf = new ResultForm();
            rf.Show();
        }
        else if (usertextBox.Text == "" || paswordTextBox.Text == "")
        {
            Notificarion2.Text = "PLEASE FILL THE BOXES !!!";
        }
        else
        {
            Notificarion2.Text = "WRONG USER OR PASSWORD !!!";
            usertextBox.Text = "";
            paswordTextBox.Text = "";

        }
    }
}

1 个答案:

答案 0 :(得分:0)

您应该在SqlDataReader循环中以while读取

 while (myDataReader.Read())
 {
   //your code goes here
 }

 myDataReader.Close();

http://msdn.microsoft.com/en-us/library/haa3afyz%28v=vs.110%29.aspx