Datarow can't bind to datagrid...I need a workaround

H

HelpPlease

I am trying to bind a datarow() array to a datagrid and discovered that you can't. what do I use? I have multiple detail records for a master and the select method is returning a datarow() array that can't be bound to the grid.

I'm trying to use visual basic.net on a webform to do this. Any example would be appreciated.

thanks,
 
M

Marshal Antony

Hi,
You can create a datatable from the datatable(may be included in the
dataset) you have with structure only.
So declare a datatable,
DataTable dt=ds.Tables[0].Clone();// you can use your datatable to clone
Then your datarow collection


DataRow[] rows=whatever you do to select from the datatable;
Then iterate through the rows collection and import rows to the datatable
dt.
foreach(DataRow dr in rows)

{

dt.ImportRow(dr);

}


Then bind datatable dt to the datagrid.

Hope this helps.

Regards,

Marshal Antony

..NET developer

http://www.dotnetmarshal.com



HelpPlease said:
I am trying to bind a datarow() array to a datagrid and discovered that
you can't. what do I use? I have multiple detail records for a master and
the select method is returning a datarow() array that can't be bound to the
grid.
 
M

Marshal Antony

You can easily convert C# code to VB.NET.
Sorry I forgot you need VB.NET.
For eg:
Dim dt as DataTable=Yourdatatable.Clone()
Hope this helps.
Regards,
Marshal Antony
..NET Developer
http://www.dotnetmarshal.com



Marshal Antony


Marshal Antony said:
Hi,
You can create a datatable from the datatable(may be included in the
dataset) you have with structure only.
So declare a datatable,
DataTable dt=ds.Tables[0].Clone();// you can use your datatable to clone
Then your datarow collection


DataRow[] rows=whatever you do to select from the datatable;
Then iterate through the rows collection and import rows to the datatable
dt.
foreach(DataRow dr in rows)

{

dt.ImportRow(dr);

}


Then bind datatable dt to the datagrid.

Hope this helps.

Regards,

Marshal Antony

.NET developer

http://www.dotnetmarshal.com



HelpPlease said:
I am trying to bind a datarow() array to a datagrid and discovered that
you can't. what do I use? I have multiple detail records for a master and
the select method is returning a datarow() array that can't be bound to the
grid.

I'm trying to use visual basic.net on a webform to do this. Any example would be appreciated.

thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top