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?

Recommended Answers

All 2 Replies

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).

It works !! Thanks very much:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.