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

Edited by antihero0021: code copy error

7 Years
Discussion Span
Last Post by antihero0021
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.