473,394 Members | 1,773 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,394 software developers and data experts.

DataTable.ImportRow question

Hi,

I have a question about the .NET DataTable.ImportRow method. If I
import a DataRow into an empty DataTable, will the empty DataTable pick
up the schema of the DataRow I'm trying to put into it? For example, I
have code that looks like this:

DataTable tableWithData;
DataTable emptyTable = new DataTable();
emptyTable.ImportRow(tableWithData.Rows[0]);

If I call tableWithData.Columns.Count, I get 5.
If I call emptyTable.Columns.Count before calling ImportRow, I get 0,
which is what I expect from the DataTable constructor with no
arguments...
But when I call emptyTable.Columns.Count after calling ImportRow, I
still get 0.
And just to make sure that a DataRow is being imported, calling
emptyTable.Rows.Count after the ImportRow statement gets me 1.

Does anybody know if there's some way that I can programmatically
import a DataTable's schema along with the data? Thanks.

--Jay

Jun 7 '06 #1
1 1903
"kempshall" <ja*******@gmail.com> wrote in message
news:11*********************@f6g2000cwb.googlegrou ps.com...
Hi,

I have a question about the .NET DataTable.ImportRow method. If I
import a DataRow into an empty DataTable, will the empty DataTable pick
up the schema of the DataRow I'm trying to put into it? For example, I
have code that looks like this:

DataTable tableWithData;
DataTable emptyTable = new DataTable();
emptyTable.ImportRow(tableWithData.Rows[0]);

If I call tableWithData.Columns.Count, I get 5.
If I call emptyTable.Columns.Count before calling ImportRow, I get 0,
which is what I expect from the DataTable constructor with no
arguments...
But when I call emptyTable.Columns.Count after calling ImportRow, I
still get 0.
And just to make sure that a DataRow is being imported, calling
emptyTable.Rows.Count after the ImportRow statement gets me 1.

Does anybody know if there's some way that I can programmatically
import a DataTable's schema along with the data? Thanks.


emptyTable = tableWithData.Clone(); creates an empty table with the schema
from tableWithData.

Chris Jobson
Jun 7 '06 #2

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

Similar topics

3
by: Matthew Wieder | last post by:
I have a datatable as a source and I need to produce a datatable which is all the rows in the original datatable except the first row, copied n times. So, if I had a datatable of: A B C...
1
by: Ersin Gençtürk | last post by:
I have 2 typed data tables inherited from the same dataset schema One called : table A with an identity column x column x is constrained to be unique. Other one is : table B with an identity...
3
by: Gene Hubert | last post by:
I'm using DataTable.ImportRow to move data from one datatable to another... Dim dt, dtTarget As DataTable Dim dr As DataRow dt = DirectCast(Me.DataSource, DataTable) dtTarget = dt.Clone...
6
by: Doug Bell | last post by:
Hi, Is there a more efficient way to append the rows of a DataTable to a second DataTable that has the same structure? Currently I am using a For Next loop: Dim drSource, drTarget as DataRow...
12
by: Doug Bell | last post by:
Hi, I am having problems trying to create a (temporary) DataTable from a selection from a DataGrid (dgOrders). dtOrdDetails is declared as a Public DataTable Sub is: Dim stFilter as String...
4
by: hharry | last post by:
hello all, i have 2 datatables and am trying to transfer rows from datatable a to datatable b i use the datatable.importrow method. the importrow method fails (but does not throw an...
1
by: kempshall | last post by:
Hi, I have a question about the .NET DataTable.ImportRow method. If I import a DataRow into an empty DataTable, will the empty DataTable pick up the schema of the DataRow I'm trying to put into...
2
by: neilr | last post by:
Can anyone help with some problkems that have wasted 2 days of my (inexperienced) time already? We have a website which allows people to register for events like conferences We are importing...
6
by: Pete Wittig | last post by:
Hi, I have a DataTable and I want to get a subset of the rows within it. I use the Select method to get my subset and the results are in a DataRow. I want to put those Rows back into a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.