0

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 by leo88: n/a

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by leo88
0

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 by Mitja Bonca: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.