0
had troubles with the GetSchemaTable()
here's how i got it to work:
System.Data.OleDb.OleDbDataReader dr = comm.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
System.Data.DataTable dt = new DataTable();
for (int i=0; i
0
Tath's right, but we want to know how to populate a DataGrid from a DataReader.
is it possible?
thank you.
regards.
0
Hi
It is not DataBind(). It is somthig like this:
dataGrid1.SetDataBinding(dsPersonel,"Personel");
dsPersonnel is Dataset and Personel is the table in the dataset
0
I don't know the two fifferent datagrids. I'm using the datagrid from the toolbar and it doesn't have the method DataBind().
can somebody gives a solution please
0
can you please fully qualify the objects you are using, as there are two different datagrid objects. This will make it easier, as I also have this problem.
Thanks!
0
Instead of OleDbCommand etc try using SqlCommand etc.
0
CrendKing, the code that you wrote it doesn't work, may be because I'm usig a SQL Server connection. If you have the solution for SQL, I'd thank you.
0
Try this code, it works in my computer, and it's simple :) (C# Code)
conn is OleDbConnection, cmd is OleDbCommand, dr is OleDbDataReader, dg is DataGrid.
conn.Open();
cmd = new OleDbCommand("SELECT * FROM vote", conn); // Use Constructor
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
dg.DataSource = dr;
dg.DataBind();
0
This is really stupid. I say that there are two major flaws in .NET. First, there is no one-stop way to convert a char[] to a byte[], even though you can cast a char to a byte, you can't cast a char[] to a byte[]. The second is that you cannot assign a datareader to a dataset. Who cares if it's read only forward only while it's connected? Data is data and once it's disconnected, let the dataset move back and forth. It's supposed to be disconnected dataset-oriented, but it's still bound to this stupid connected cursor crap. GARBAGE!
I have done this anyway. For the reasons I've described, this should be possible, and it is. You just have to do it manually.
Create a dataset ds. Declare a datatable dt. Open your datareader dr. Execute this:
DataTable dt = dr.GetSchemaTable;
}
Create an object array named rowdata. For each row in dr, get each column as an object and assign it to the corresponding element in rowdata. Then, add the rowdata to the table with
dt.Rows.Add(rowdata);
Finally, add the datatable to the dataset like this:
ds.Tables.Add(dt);
With the data in a dataset, you can bind the dataset to the grid.

0
Check out the MS article at :
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q313/4/82.asp&NoWebContent=1&NoWebContent=1
Quote: "Unlike ASP.NET Web Forms, the Windows Forms object model does not support binding to the DataReader object or the IEnumerable interface because backward scrolling support is required when you bind to anything other than a simple object."
- dip