Hi, I am doing login using data reader of C#. Here is my codes,

try
           {
           Access_Db.OpenTransaction();
           Access_Db.BeginTransaction();

           bool usrExist = false;
           string SQLStr = "SELECT ID,Password FROM RegisterEmployee";
           OleDbCommand sqlComm = new OleDbCommand(SQLStr);
           OleDbDataReader reader = sqlComm.ExecuteReader(); // program got exception when run till here          
       
            while(reader.Read())
            {               
                if (reader["ID"].ToString() == usrfield.Text.ToString() && reader["Password"].ToString() == passdField.Text.ToString())
                     {
                        usrExist=true;
                     }           
                 else
                     {
                        usrExist=false;
                     }
            }
            reader.Close();

When I executed the program, an exception "Connecton property not initialized for ExecuteReader" had occured. What had happened?

Edited 5 Years Ago by leo88: n/a

Where do you have:

SqlConnection sqlConn = new SqlConnection("connString");

amd for to Read data, you have to opean a connection as well:

sqlConn.Open();

And its good to close it on the end of the code (or use "using" keywords instead).

Edited 5 Years Ago by Mitja Bonca: n/a

This question has already been answered. Start a new discussion instead.