Good morning, i have an issue with my code but i dont know what it is. i'm trying to get the names of all tables in an access database, use their names to open the tables and pick some of their data using a datareader, but i keep getting System.InvalidOperationException
no data for row/column. please what am i doing wrong? or if possible can anyone give me alternative code to achieve what i want. i dont want to use a datatable or bind the datareader to the datagridview because it isnt all the data from the tables i
need, just from some columns.
privatevoidForm1_Load(object sender,EventArgs e){try{OleDbConnectionConnection=newOleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\BolorunduroWB\\Documents\\Access\\MainClientDataFile.mdb;Persist Security Info=False;");DataTable userTables =null;string[] restrictions =newstring[4]; restrictions[3]="Table";Connection.Open(); userTables =Connection.GetSchema("Tables", restrictions);for(int i =0; i < userTables.Rows.Count; i++){string query ="SELECT * FROM "+ userTables.Rows[i][2];OleDbConnection conn =newOleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\BolorunduroWB\\Documents\\Access\\MainClientDataFile.mdb;Persist Security Info=False;");OleDbCommand cmd =newOleDbCommand(); cmd.Connection= conn; cmd.CommandText="SELECT * FROM "+ userTables.Rows[i][2].ToString(); conn.Open();OleDbDataReader reader = cmd.ExecuteReader();if(reader.HasRows){ reader.Read(); dataGridView1.Rows.Add(); dataGridView1.Rows[i].Cells[0].Value= reader[0].ToString(); reader.Read(); dataGridView1.Rows[i].Cells[1].Value= reader[0].ToString(); reader.Read(); dataGridView1.Rows[i].Cells[2].Value= reader[0].ToString(); reader.Close();}}}catch(Exception ex){MessageBox.Show(ex.ToString());}}