I'm using a third-party tool that takes a DataTable as a parameter. I really
need to pass it a DataView instead. When I try to explicitly cast the
DataView as a DataTable I get an error that they aren't compatible data
types. Does anyone have a suggestion on how to do this?

My last resort is to create a new DataTable object and copy the rows from
the DataView into the DataTable. But this is an ugly hack and I really hope
there is a better solution.

Thanks.

Re: Cast DataView as a DataTable by Mark

Mark
Tue Jan 20 19:52:53 CST 2004

Can't do it. You can access the table that is part of the DataView using the
DataView.Table property, but otherwise they're two way different beasties so
you can't cast them.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP- FrontPage

"Brian Bischof" <brian@nospam.bischofsystems.com> wrote in message
news:emA2PA83DHA.540@tk2msftngp13.phx.gbl...
> I'm using a third-party tool that takes a DataTable as a parameter. I
really
> need to pass it a DataView instead. When I try to explicitly cast the
> DataView as a DataTable I get an error that they aren't compatible data
> types. Does anyone have a suggestion on how to do this?
>
> My last resort is to create a new DataTable object and copy the rows from
> the DataView into the DataTable. But this is an ugly hack and I really
hope
> there is a better solution.
>
> Thanks.
>
>



Re: Cast DataView as a DataTable by Brian

Brian
Tue Jan 20 21:13:27 CST 2004


Thanks for the info. I wrote a method to create a new table based off the
original table structure and then add the rows into it. Lots of loops!

Brian



"Mark Fitzpatrick" <markfitz@fitzme.com> wrote in message
news:O9qfJF83DHA.560@TK2MSFTNGP11.phx.gbl...
> Can't do it. You can access the table that is part of the DataView using
the
> DataView.Table property, but otherwise they're two way different beasties
so
> you can't cast them.
>
> Hope this helps,
> Mark Fitzpatrick
> Microsoft MVP- FrontPage
>
> "Brian Bischof" <brian@nospam.bischofsystems.com> wrote in message
> news:emA2PA83DHA.540@tk2msftngp13.phx.gbl...
> > I'm using a third-party tool that takes a DataTable as a parameter. I
> really
> > need to pass it a DataView instead. When I try to explicitly cast the
> > DataView as a DataTable I get an error that they aren't compatible data
> > types. Does anyone have a suggestion on how to do this?
> >
> > My last resort is to create a new DataTable object and copy the rows
from
> > the DataView into the DataTable. But this is an ugly hack and I really
> hope
> > there is a better solution.
> >
> > Thanks.
> >
> >
>
>



Re: Cast DataView as a DataTable by Jay

Jay
Wed Jan 21 08:06:07 CST 2004

Brian,
You do realize that you can use DataTable.Clone to "create a new table based
off the original table structure"?

Then you only need a single loop to add the respective rows to the new
DataTable.

Unless of course you are modifying the structure itself of the original
DataTable.

BTW: DataTable.Clone will copy the structure of an existing DataTable, while
DataTable.Copy will copy the structure & data of an existing DataTable.

Hope this helps
Jay

"Brian Bischof" <brian@nospam.bischofsystems.com> wrote in message
news:uhW1Ly83DHA.3944@tk2msftngp13.phx.gbl...
>
> Thanks for the info. I wrote a method to create a new table based off the
> original table structure and then add the rows into it. Lots of loops!
>
> Brian
>
>
>
> "Mark Fitzpatrick" <markfitz@fitzme.com> wrote in message
> news:O9qfJF83DHA.560@TK2MSFTNGP11.phx.gbl...
> > Can't do it. You can access the table that is part of the DataView using
> the
> > DataView.Table property, but otherwise they're two way different
beasties
> so
> > you can't cast them.
> >
> > Hope this helps,
> > Mark Fitzpatrick
> > Microsoft MVP- FrontPage
> >
> > "Brian Bischof" <brian@nospam.bischofsystems.com> wrote in message
> > news:emA2PA83DHA.540@tk2msftngp13.phx.gbl...
> > > I'm using a third-party tool that takes a DataTable as a parameter. I
> > really
> > > need to pass it a DataView instead. When I try to explicitly cast the
> > > DataView as a DataTable I get an error that they aren't compatible
data
> > > types. Does anyone have a suggestion on how to do this?
> > >
> > > My last resort is to create a new DataTable object and copy the rows
> from
> > > the DataView into the DataTable. But this is an ugly hack and I really
> > hope
> > > there is a better solution.
> > >
> > > Thanks.
> > >
> > >
> >
> >
>
>