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

datatable.import row bug/issue

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 exception) when
importing a datarow that has numeric columns. columns of type string
are imported fine.

e.g.

Dim objManualDataSet As DataSet
objMasterDataSet.Tables.Add(New DataTable(TableNames.Unique_DoB))

objMasterDataSet.Tables(TableNames.Unique_DoB).Col umns.Add(New
DataColumn("dob_key", System.Type.GetType("System.String")))

objMasterDataSet.Tables(TableNames.Unique_DoB).Col umns.Add(New
DataColumn("mn", System.Type.GetType("System.Int16")))

objMasterDataSet.Tables(TableNames.Unique_DoB).Col umns.Add(New
DataColumn("dd", System.Type.GetType("System.Int16")))

objMasterDataSet.Tables(TableNames.Unique_DoB).Col umns.Add(New
DataColumn("yy", System.Type.GetType("System.Int16")))

My 2nd dataset is generated by a call to a sql stored proc and has the
same structure as the 1st dataset..

My code to import the row is:

For Each objRow As DataRow In objManualDataSet.Tables(2).Rows
objMasterDataSet.Tables(TableNames.Unique_DoB).Imp ortRow(objRow)
Next

This is the result:

? objManualDataSet.Tables(2).Rows(0).ItemArray
{Length=4}
(0): "mn=1dd=12yy=1955"
(1): 1 {Short}
(2): 12 {Short}
(3): 1955 {Integer}
? objMasterDataSet.Tables(TableNames.Unique_DoB).Row s(0).ItemArray
{Length=4}
(0): "mn=3dd=29yy=1973"
(1): {System.DBNull}
(2): {System.DBNull}
(3): {System.DBNull}

Any ideas as to why cols 1, 2, 3 = System.DBNull ?

Thanks in advance

May 12 '06 #1
4 4929
hharry wrote:
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 exception) when
importing a datarow that has numeric columns. columns of type string
are imported fine.

e.g.

Dim objManualDataSet As DataSet
objMasterDataSet.Tables.Add(New DataTable(TableNames.Unique_DoB))

objMasterDataSet.Tables(TableNames.Unique_DoB).Col umns.Add(New
DataColumn("dob_key", System.Type.GetType("System.String")))

objMasterDataSet.Tables(TableNames.Unique_DoB).Col umns.Add(New
DataColumn("mn", System.Type.GetType("System.Int16")))

objMasterDataSet.Tables(TableNames.Unique_DoB).Col umns.Add(New
DataColumn("dd", System.Type.GetType("System.Int16")))

objMasterDataSet.Tables(TableNames.Unique_DoB).Col umns.Add(New
DataColumn("yy", System.Type.GetType("System.Int16")))

My 2nd dataset is generated by a call to a sql stored proc and has the
same structure as the 1st dataset..

My code to import the row is:

For Each objRow As DataRow In objManualDataSet.Tables(2).Rows
objMasterDataSet.Tables(TableNames.Unique_DoB).Imp ortRow(objRow)
Next

This is the result:

? objManualDataSet.Tables(2).Rows(0).ItemArray
{Length=4}
(0): "mn=1dd=12yy=1955"
(1): 1 {Short}
(2): 12 {Short}
(3): 1955 {Integer}
? objMasterDataSet.Tables(TableNames.Unique_DoB).Row s(0).ItemArray
{Length=4}
(0): "mn=3dd=29yy=1973"
(1): {System.DBNull}
(2): {System.DBNull}
(3): {System.DBNull}

Any ideas as to why cols 1, 2, 3 = System.DBNull ?

Thanks in advance


I don't think you can do this. I seem to remember an issue that rows
can not be attached to two datatables at once. I could be wrong though.
Have you thought about cloning the datatable.

DataTable.Clone

May 12 '06 #2
Chris,

Yes, I tried using the Add method and got the row cannot belong to more
than one datatable error. The ImportRow method worlks fine if all
columns are of type string. I only get the error if any columns are
numeric.

May 12 '06 #3
here is my workaround:

For Each objRow As DataRow In objManualDataSet.Tables(2).Rows
Dim tmpRow(3) As Object
tmpRow(0) = objRow.Item(0)
tmpRow(1) = objRow.Item(1)
tmpRow(2) = objRow.Item(2)
tmpRow(3) = objRow.Item(3)

objMasterDataSet.Tables(TableNames.Unique_DoB).Loa dDataRow(tmpRow,
True)
Next

May 12 '06 #4
You could try using something like this

objMasterDataSet.Tables(TableNames.Unique_DoB).Row s.Add(objRow.ItemArray)

in place of

objMasterDataSet.Tables(TableNames.Unique_DoB).Imp ortRow(objRow)

This call will depend on the Columns of both tables having the same
indexes or it will error (Mismatched data types) or worse - it will
copy the wrong data to the wrong columns.

May 12 '06 #5

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

Similar topics

2
by: Scott | last post by:
I am using DTS to import tables into my new database from another database, both of which reside on the same server. All the tables, fields and data copy over fine; however when I go into design...
8
by: Buddy | last post by:
Hello, We are using DataTable to store our data that we retrieve from SQL because it provides us with ROW/COLUMN concept. Due to DataTable been memory hungary we are finding that at least 40MB...
0
by: pavan | last post by:
hi, Please refer this article because that is the dll iam using for compression/decompression of datatables. http://www.eggheadcafe.com/articles/20031219.asp This is a windows application in C#...
0
by: pavan kumar | last post by:
hi, Please refer this article because that is the dll iam using for compression/decompression of datatables. http://www.eggheadcafe.com/articles/20031219.asp This is a windows application in C#...
2
by: Pascal | last post by:
I have a file with data i'd like to import into my relational dbs. The file looks like this: Name age job Tom 23 Programmer John 48 Manager Karin 22...
3
by: praveenkumar.117 | last post by:
Hi All, What is the difference between import string and from string import * Regards, Praveen
7
by: Varangian | last post by:
Hi all, the question I want to ask if the conversion of a DataReader to a Table looping through the DataReader is better than using the Fill Method of the DataAdapter... I'm asking because...
3
by: ApeX | last post by:
hello, can anybody please give me some advice or a pseudocode for the following: i got two datatables filled with dates, i need to fill a third datatable with values from the other two but the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.