473,378 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Cast DataView as a DataTable

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.
Nov 15 '05 #1
3 9773
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" <br***@nospam.bischofsystems.com> wrote in message
news:em*************@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.

Nov 15 '05 #2

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" <ma******@fitzme.com> wrote in message
news:O9*************@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" <br***@nospam.bischofsystems.com> wrote in message
news:em*************@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.


Nov 15 '05 #3
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" <br***@nospam.bischofsystems.com> wrote in message
news:uh**************@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" <ma******@fitzme.com> wrote in message
news:O9*************@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" <br***@nospam.bischofsystems.com> wrote in message
news:em*************@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.



Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Li Weng | last post by:
Hi, I use a DataView to display a State field. But some rows have the same state like 'OH'. How can I just display only one of them like SQL's DISTINCT? Can I use .rowfilter? How? I don't have...
1
by: GeraldBauer | last post by:
I am experiencing some weird behaviors with the listbox and dataview. Here is a boiled down code snippet of what I am trying to do. <snippet> string MENUID = "MenuId" , ITEM = "Item" ,...
1
by: James | last post by:
code: public void Initialize(short A1, string A2,short A3, short A4, short A5, short RecNo) { DataTable myTable = new DataTable("myTable"); DataColumn colItem0 = new
3
by: nandan | last post by:
Hi, Has any one ever compared the performance of calling a DataTable's Select method with a stored procedure doing the same thing? My point is: dataRows = DataTable.Select(filter) is better or...
5
by: enceladus311 | last post by:
I'm trying to find a way to keep from having to fill a DataView after every PostBack to a page. Basically, the design is that I have a DataView that I fill, which I then set as the DataSource to a...
0
by: Nathan Franklin | last post by:
Hello Guys, I have been trying to work this our for so long, but I just can't seem to find the answer. I am loading a datatable from a an access database using an oledbdataadapter. I then...
6
by: Nick | last post by:
I have a code that returns data in IList. My webGrid doesn't allow me to sort with IList returned, it say it only suports DataView, DataTable and DataSet, not IEnumerable. I don't know how to...
2
by: WandaLL | last post by:
I have several columns which I've sorted but the Date Field sorts as a string rather than as a date and I can't seem to figure out how to fix that. Below is my code. Thanks for your help. ...
0
by: Chet | last post by:
I have a Datagrid that is bound to a Datatable at runtime. I allow the user to select a number of rows using the mouse and then click a button that says "check selected rows", which then cycles...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.