0

Trying to bind the data that I recover from ADO query, I am getting the same error after trying different approach (usaing dataTable, DataView,...). The last one I used is the next:

string query = "SELECT * FROM productos";
MySqlConnection con = new MySqlConnection(connectionString);
MySqlCommand cmd = new MySqlCommand("select * from productos");
con.Open();
cmd.Connection = con;
MySqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();

Another approach I used was:

MySqlConnection Com = new MySqlConnection(connectionString);
MySqlCommand cmd = new MySqlCommand(query);
Com.Open();
cmd.Connection = Com;
Datos = cmd.ExecuteReader();
dt.Load(Datos);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();

The error returned in all cases is:

System.InvalidOperationException: 'Cannot determine table from data source. Use the MetaTable.MapTable method to establish an association between a data source and a MetaTable instance.'

Isma
  • 14,604
  • 5
  • 37
  • 51
Kenzo_Gilead
  • 2,187
  • 9
  • 35
  • 60

0 Answers0