Use Datareader to fill Datagrid ??

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

Rikki

.....impossible ???

I can't find any information on this, so i'm beginning to believe that it
can't be done(?)

I'm thankful for any information on this!!
 
Hi Rikki,
....impossible ???

I can't find any information on this, so i'm beginning to believe that it
can't be done(?)

It is impossible to fill DataGrid directly, but You can do it
indirectly.

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

Regards

Marcin
 
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 would not use the data reader to populate the data table directly.
Rather, I would create a data adapter, passing in your command and then
passing a dataset to the Fill method. Once you call Fill, the data set will
be populated with the data from the query.

Hope this helps.


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


Rikki said:
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