Question

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 = "";

        }
    }
}
Was it helpful?

Solution

You should read from SqlDataReader in a while loop as

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

 myDataReader.Close();

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top