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 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
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.
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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#...
|
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#...
|
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...
|
by: praveenkumar.117 |
last post by:
Hi All,
What is the difference between
import string
and
from string import *
Regards,
Praveen
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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...
| |