Salve a tutti.
Premetto che vengo da PHP e sono nuovo in ambiente .NET
Volevo chiedervi secondo voi cos'ha che non va questo codice:
Chiaramente "reader" è stato già aperto da una query tipo:codice:DataTable Test(OdbcDataReader reader) { DataTable table = new DataTable(); table.Columns.Add("id", typeof(int)); while (reader.Read()) { DataRow row = dt.NewRow(); // la seguente riga genera l'eccezione InvalidCastOperation row["id"] = reader.IsDBNull(0) ? 0 : reader.GetInt32(0); } return table; }
"SELECT id FROM tabella"
dove "id" è un campo di tipo int della simbolica tabella "tabella" mysql
Grazie

Rispondi quotando