R
Ryan
I have 2 Access '97 databases. I am trying to migrate all the data from one
to the other (append to existing records). I do not have Access '97 and
opening with Access XP or later causes problems. I have found I can connect
to the databases in Visual Studio 2005 and insert records, etc, so I'm
trying to write my code using VB 2005.
I have 2 connections, 2 datasets... OldDS and NewDS. First I populate both
datasets:
OldDS.TableAdapter1.Fill(OldDS.Table1)
NewDS.TableAdapter1.Fill(NewDS.Table1)
This works fine, I've queried the datasets, they are both populated with
data from the tables, ready to go.
Here's where I have the problem, transferring data from the old dataset into
the new one. I've tried numerous approaches, here is the most recent
attempt:
For i As Integer = 0 To oldDS.Table1.Count - 1
' Copy Row from oldDataSet, INSERT into newDataSet
Dim r As DataRow = oldDS.Table1.Rows(i)
newDS.Table1.AddTable1Row(r.Item(0), r.Item(1), r.Item(2), r.Item(3),
r.Item(4))
Me.ProgressBar1.Increment(1)
Next
What happens is I get constraint errors.. type "DBNull" cannot be converted
to <insert type here>. I have checked both Datasets and constraints are
OFF. Why would it do this? All fields should allow Null values, but any
Nulls in the Old table are causing all sorts of problems. I've set the
default for Strings to (Empty) using the dataset designer and this seems to
help those fields but any other field type (DateTime for example) will throw
an exception.
Thanks,
Ryan
to the other (append to existing records). I do not have Access '97 and
opening with Access XP or later causes problems. I have found I can connect
to the databases in Visual Studio 2005 and insert records, etc, so I'm
trying to write my code using VB 2005.
I have 2 connections, 2 datasets... OldDS and NewDS. First I populate both
datasets:
OldDS.TableAdapter1.Fill(OldDS.Table1)
NewDS.TableAdapter1.Fill(NewDS.Table1)
This works fine, I've queried the datasets, they are both populated with
data from the tables, ready to go.
Here's where I have the problem, transferring data from the old dataset into
the new one. I've tried numerous approaches, here is the most recent
attempt:
For i As Integer = 0 To oldDS.Table1.Count - 1
' Copy Row from oldDataSet, INSERT into newDataSet
Dim r As DataRow = oldDS.Table1.Rows(i)
newDS.Table1.AddTable1Row(r.Item(0), r.Item(1), r.Item(2), r.Item(3),
r.Item(4))
Me.ProgressBar1.Increment(1)
Next
What happens is I get constraint errors.. type "DBNull" cannot be converted
to <insert type here>. I have checked both Datasets and constraints are
OFF. Why would it do this? All fields should allow Null values, but any
Nulls in the Old table are causing all sorts of problems. I've set the
default for Strings to (Empty) using the dataset designer and this seems to
help those fields but any other field type (DateTime for example) will throw
an exception.
Thanks,
Ryan