Trying to use an oledbdatareader to search through a table in my Access database. When I hit the command button to search it throws an error that says no data exists for row/column, but if I execute the command against the database it returns exactly what I am looking for. I've tried doing some looking, but I was unable to find an answer to what I am looking to do. It seems to find the value for reader.getint32(0) but not for reader.getstring(1) or anything after that.

string sqlEmployeeSearch = "Select * from tblEmployee WHERE F_Name = ?;";

            string dbconnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\WSC_teama.mdb;User Id=admin;Password="; 
            OleDbConnection objConnection = new OleDbConnection(dbconnect); 
            OleDbCommand objCommand = new OleDbCommand(sqlEmployeeSearch, objConnection); 
            OleDbDataReader reader = null; 

            OleDbParameter pFName = new OleDbParameter(); 
            pFName.Value = tempFName;


            reader = objCommand.ExecuteReader();
                while (reader.Read())

                    compEmpNum = reader.GetInt32(0).ToString();
                    compFName = reader.GetString(1);
                    compLName = reader.GetString(2);
                    compAddress = reader.GetString(3);
                    compCity = reader.GetString(4);
                    compState = reader.GetString(5);
                    compSalary = reader.GetDouble(6).ToString();
                    compTitle = Int32.Parse(reader.GetString(7));

            catch (Exception ex)
                MessageBox.Show("read meathod " + ex);
                //error message that shows if connection or search string fails.


Any help would be appreciated.

- antihero0021

Recommended Answers

All 2 Replies

Line #17 : Curly braces are missing.



Boy is my face red. Can't believe I missed that. Thanks for the help!

Be a part of the DaniWeb community

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