DataReader -> Datagrid

  • Thread starter Thread starter Rikki
  • Start date Start date
R

Rikki

Marcin wrote :
e.g. If you define DataTable object, You can load it with IDataReader
values and then set its table as a DataSource of DataGrid.

Ok, i'm a beginner with C# ...

i have tried this :
connection = new OleDbConnection(connStr);
connection.Open();
OleDbCommand myCommand = new OleDbCommand(sqlTable,connection);
OleDbDataReader myReader;
myReader = myCommand.ExecuteReader();
myReader.Read();
DataTable dataTable = new DataTable("Table");
..... but somthing is dead wrong here:
datatable.Columns[0].DefaultValue = myReader.GetValue(0).ToString();
dataGrid1.DataSource = dataTable;
myReader.Close();
connection.Close();

....can you help me out ??
 
Rikki,

I am curious, instead of setting the values in the data table yourself,
why not call the Fill method on a data adapter (which has the select command
set to your select), and have it fill a data set for you? You can then bind
this data set to a grid.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rikki said:
Marcin wrote :
e.g. If you define DataTable object, You can load it with IDataReader
values and then set its table as a DataSource of DataGrid.

Ok, i'm a beginner with C# ...

i have tried this :
connection = new OleDbConnection(connStr);
connection.Open();
OleDbCommand myCommand = new OleDbCommand(sqlTable,connection);
OleDbDataReader myReader;
myReader = myCommand.ExecuteReader();
myReader.Read();
DataTable dataTable = new DataTable("Table");
.... but somthing is dead wrong here:
datatable.Columns[0].DefaultValue = myReader.GetValue(0).ToString();
dataGrid1.DataSource = dataTable;
myReader.Close();
connection.Close();

...can you help me out ??
 
Back
Top