473,803 Members | 3,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9811
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.b ischofsystems.c om> wrote in message
news:em******** *****@tk2msftng p13.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******@fitzm e.com> wrote in message
news:O9******** *****@TK2MSFTNG P11.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.b ischofsystems.c om> wrote in message
news:em******** *****@tk2msftng p13.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.b ischofsystems.c om> wrote in message
news:uh******** ******@tk2msftn gp13.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******@fitzm e.com> wrote in message
news:O9******** *****@TK2MSFTNG P11.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.b ischofsystems.c om> wrote in message
news:em******** *****@tk2msftng p13.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
5836
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 to use DataView. If DataTable can do it, it's ok too. Thanks in advance. Li
1
6793
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" , MENU_ENTRY_ID = "MenuEntryId"; private void populateMenu() {
1
299
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
5907
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 Passing paramters to stored procedure? The datatable holds about 500-700 rows at any given time. If I select one of the approaches the business logic will go into respective layers.With dotnet in picture what would be a good approach
5
3966
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 DataGrid on my page. This works well, however, like I said, I would like to keep from having to fill the DataView on each PostBack. So, naturally, what I did was checked whether or not the request was a PostBack by checking the IsPostBack...
0
1844
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 assign the datatable.dataview to my datagrid.datasource member so it will display my results.. I need to give the user an option to change the order of this data, I have a
6
16744
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 return the DataSet type when using the following code: ======== this is my interface ====================== namespace WareHouse.DataLayer.DataObjects { /// <summary> /// Defines methods to access categories and products.
2
1397
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. public partial class MyProjects : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e)
0
1473
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 through the selected rows and sets a check box field in the datagrid (and thus the databound datatable) to checked/true. It works like this: Dim cel As DataGridViewCheckBoxCell For Each row In DataGrid.SelectedRows cel = row.Cells(0) cel.Value =...
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10546
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10292
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6841
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.