473,394 Members | 1,642 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.

LoadDataRow Issues

VJ
I have 2 datasets, each with a DataTable. Each table has the same primary
key, and columns. I am trying to copy rows from one dataset to another,
based on an event from my application.

It all works fine when the row is not present in the destination DataTable.
Now when the row is present in the destination file, the .NET documentation
says use the LoadRowData method of the dataset to copy the row. When do
this, I get a unique key violation problem (right at the EndLoadData point
in the code below).. Here is my code below. Can anybody help??
Dim app As Application
Dim xmlDestFile As String = app.StartupPath & "\" & "dest.xml"
Dim xmlSourceFile As String = app.StartupPath & "\" & "source.xml"
Dim dsDest As New DataSet
Dim dsSource As New DataSet
Dim rwDest As DataRow
Dim rwSource As DataRow

dsDest.ReadXml(xmlDestFile)
dsSource.ReadXml(xmlDestFile)

Try
For Each rwSource In dsSource.Tables(0).Rows
Dim copyRowPersent As Boolean

For Each rwDest In dsDest.Tables(0).Rows
If rwDest.Item("Name") = rwSource.Item("Name") Then
copyRowPersent = True
Exit For
End If
Next

If copyRowPersent Then

Dim newRow(rwSource.Table.Columns.Count - 1) As Object
Dim column As DataColumn
Dim intLoop As Int32

intLoop = 0

For Each column In rwSource.Table.Columns
newRow(intLoop) = rwSource.Item(column)
intLoop = intLoop + 1
Next

dsDest.Tables(0).BeginLoadData()
dsDest.Tables(0).LoadDataRow(newRow, False)
dsDest.Tables(0).EndLoadData() ' I get a
primary key voilation problem here..., I don't even go to accept changes

else
'Import the new rows here using ImportRow
' This works fine...

End If

Next

dsDest.AcceptChanges()
dsDest.WriteXml(xmlDestFile, XmlWriteMode.WriteSchema)
dsDest.Dispose()
dsSource.Dispose()

Catch myex As Exception

MsgBox(myex.ToString, MsgBoxStyle.Information +
MsgBoxStyle.OKOnly, "Test")

End Try
VJ

Nov 20 '05 #1
3 2705
According to help, EndLoadData does the following:
Turns on notifications, index maintenance, and constraints after
loading data.
Since it enables the constraints, any unique key constraints will be
enabled, and thus an exception gets thrown because you have two rows with
the same unique key.

Depending on your situation, you will either have to update your unique
key, or update the row that the prior unique key was on.

Josh Moody
VSU Team

--

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
--------------------
From: "VJ" <vi********@yahoo.com>
Subject: LoadDataRow Issues
Date: Fri, 21 Nov 2003 12:39:06 -0600
Lines: 76
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#r**************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb,microsoft.pub lic.dotnet.framework.adone
tNNTP-Posting-Host: adsl-68-90-207-131.dsl.rcsntx.swbell.net 68.90.207.131
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!cpmsftng xa09.phx.gbl!TK2MSFTNGP08.
phx.gbl!TK2MSFTNGP10.phx.gblXref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.adonet:66814 microsoft.public.dotnet.languages.vb:158111X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I have 2 datasets, each with a DataTable. Each table has the same primary
key, and columns. I am trying to copy rows from one dataset to another,
based on an event from my application.

It all works fine when the row is not present in the destination DataTable.
Now when the row is present in the destination file, the .NET documentation
says use the LoadRowData method of the dataset to copy the row. When do
this, I get a unique key violation problem (right at the EndLoadData point
in the code below).. Here is my code below. Can anybody help??
Dim app As Application
Dim xmlDestFile As String = app.StartupPath & "\" & "dest.xml"
Dim xmlSourceFile As String = app.StartupPath & "\" & "source.xml"
Dim dsDest As New DataSet
Dim dsSource As New DataSet
Dim rwDest As DataRow
Dim rwSource As DataRow

dsDest.ReadXml(xmlDestFile)
dsSource.ReadXml(xmlDestFile)

Try
For Each rwSource In dsSource.Tables(0).Rows
Dim copyRowPersent As Boolean

For Each rwDest In dsDest.Tables(0).Rows
If rwDest.Item("Name") = rwSource.Item("Name") Then
copyRowPersent = True
Exit For
End If
Next

If copyRowPersent Then

Dim newRow(rwSource.Table.Columns.Count - 1) As Object
Dim column As DataColumn
Dim intLoop As Int32

intLoop = 0

For Each column In rwSource.Table.Columns
newRow(intLoop) = rwSource.Item(column)
intLoop = intLoop + 1
Next

dsDest.Tables(0).BeginLoadData()
dsDest.Tables(0).LoadDataRow(newRow, False)
dsDest.Tables(0).EndLoadData() ' I get a
primary key voilation problem here..., I don't even go to accept changes

else
'Import the new rows here using ImportRow
' This works fine...

End If

Next

dsDest.AcceptChanges()
dsDest.WriteXml(xmlDestFile, XmlWriteMode.WriteSchema)
dsDest.Dispose()
dsSource.Dispose()

Catch myex As Exception

MsgBox(myex.ToString, MsgBoxStyle.Information +
MsgBoxStyle.OKOnly, "Test")

End Try
VJ


Nov 20 '05 #2
VJ
I have 2 datasets, each with a DataTable. Each table has the same primary
key, and columns. I am trying to copy rows from one dataset to another,
based on an event from my application.

It all works fine when the row is not present in the destination DataTable.
Now when the row is present in the destination file, the .NET documentation
says use the LoadRowData method of the dataset to copy the row. When do
this, I get a unique key violation problem (right at the EndLoadData point
in the code below).. Here is my code below. Can anybody help??
Dim app As Application
Dim xmlDestFile As String = app.StartupPath & "\" & "dest.xml"
Dim xmlSourceFile As String = app.StartupPath & "\" & "source.xml"
Dim dsDest As New DataSet
Dim dsSource As New DataSet
Dim rwDest As DataRow
Dim rwSource As DataRow

dsDest.ReadXml(xmlDestFile)
dsSource.ReadXml(xmlDestFile)

Try
For Each rwSource In dsSource.Tables(0).Rows
Dim copyRowPersent As Boolean

For Each rwDest In dsDest.Tables(0).Rows
If rwDest.Item("Name") = rwSource.Item("Name") Then
copyRowPersent = True
Exit For
End If
Next

If copyRowPersent Then

rwDest.delete
rwDest.Tables(0).ImportRow(rwSource)

' Dim newRow(rwSource.Table.Columns.Count - 1) As Object
' Dim column As DataColumn
' Dim intLoop As Int32

' intLoop = 0

' For Each column In rwSource.Table.Columns
' newRow(intLoop) = rwSource.Item(column)
' intLoop = intLoop + 1
' Next

' dsDest.Tables(0).BeginLoadData()
' dsDest.Tables(0).LoadDataRow(newRow, False)
' dsDest.Tables(0).EndLoadData() ' I get a
primary key voilation problem here..., I don't even go to accept changes

else
'Import the new rows here using ImportRow
' This works fine...

End If

Next

dsDest.AcceptChanges()
dsDest.WriteXml(xmlDestFile, XmlWriteMode.WriteSchema)
dsDest.Dispose()
dsSource.Dispose()

Catch myex As Exception

MsgBox(myex.ToString, MsgBoxStyle.Information +
MsgBoxStyle.OKOnly, "Test")

End Try
VJ


Nov 20 '05 #3
VJ
so LoadDataRow is not updating the row I am giving. It is rather inserting
it.. The documentation says it will update when i am trying to gave the same
row... Why is it happening?

VJ

"Josh Moody [MSFT]" <Jo********@online.microsoft.com> wrote in message
news:z9**************@cpmsftngxa07.phx.gbl...
According to help, EndLoadData does the following:
Turns on notifications, index maintenance, and constraints after loading data.
Since it enables the constraints, any unique key constraints will be
enabled, and thus an exception gets thrown because you have two rows with
the same unique key.

Depending on your situation, you will either have to update your unique
key, or update the row that the prior unique key was on.

Josh Moody
VSU Team

--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
--------------------
From: "VJ" <vi********@yahoo.com>
Subject: LoadDataRow Issues
Date: Fri, 21 Nov 2003 12:39:06 -0600
Lines: 76
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#r**************@TK2MSFTNGP10.phx.gbl>
Newsgroups:

microsoft.public.dotnet.languages.vb,microsoft.pub lic.dotnet.framework.adone t
NNTP-Posting-Host: adsl-68-90-207-131.dsl.rcsntx.swbell.net 68.90.207.131
Path:

cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!cpmsftng xa09.phx.gbl!TK2MSFTNGP08. phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.adonet:66814

microsoft.public.dotnet.languages.vb:158111
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I have 2 datasets, each with a DataTable. Each table has the same primary
key, and columns. I am trying to copy rows from one dataset to another,
based on an event from my application.

It all works fine when the row is not present in the destination DataTable.Now when the row is present in the destination file, the .NET documentationsays use the LoadRowData method of the dataset to copy the row. When do
this, I get a unique key violation problem (right at the EndLoadData pointin the code below).. Here is my code below. Can anybody help??
Dim app As Application
Dim xmlDestFile As String = app.StartupPath & "\" & "dest.xml"
Dim xmlSourceFile As String = app.StartupPath & "\" & "source.xml" Dim dsDest As New DataSet
Dim dsSource As New DataSet
Dim rwDest As DataRow
Dim rwSource As DataRow

dsDest.ReadXml(xmlDestFile)
dsSource.ReadXml(xmlDestFile)

Try
For Each rwSource In dsSource.Tables(0).Rows
Dim copyRowPersent As Boolean

For Each rwDest In dsDest.Tables(0).Rows
If rwDest.Item("Name") = rwSource.Item("Name") Then
copyRowPersent = True
Exit For
End If
Next

If copyRowPersent Then

Dim newRow(rwSource.Table.Columns.Count - 1) As Object Dim column As DataColumn
Dim intLoop As Int32

intLoop = 0

For Each column In rwSource.Table.Columns
newRow(intLoop) = rwSource.Item(column)
intLoop = intLoop + 1
Next

dsDest.Tables(0).BeginLoadData()
dsDest.Tables(0).LoadDataRow(newRow, False)
dsDest.Tables(0).EndLoadData() ' I get a
primary key voilation problem here..., I don't even go to accept changes

else
'Import the new rows here using ImportRow
' This works fine...

End If

Next

dsDest.AcceptChanges()
dsDest.WriteXml(xmlDestFile, XmlWriteMode.WriteSchema)
dsDest.Dispose()
dsSource.Dispose()

Catch myex As Exception

MsgBox(myex.ToString, MsgBoxStyle.Information +
MsgBoxStyle.OKOnly, "Test")

End Try
VJ

Nov 20 '05 #4

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

Similar topics

2
by: Tom Loredo | last post by:
Hi folks- I'm about to move from a Solaris 8/SPARC environment to a Dell running RedHat 9. Are there any issues I need to be aware of in bringing my Python code over (mostly scientific...
28
by: grahamd | last post by:
Who are the appropriate people to report security problems to in respect of a module included with the Python distribution? I don't feel it appropriate to be reporting it on general mailing lists.
2
by: malcolm | last post by:
Hello, We have a robust (.NET 1.1 c# winforms) client-server application that utilizes many typed DataSets, typed DataTables and typed DataRows. Our application is a series of windows and popup...
2
by: Dennis C. Drumm | last post by:
The description for DataTable.LoadDataRow says: Finds and updates a specific row. If no matching row is found, a new row is created using the given values. So I would think from that, that I...
2
by: VJ | last post by:
Hi.. I have 2 datasets, each with a DataTable. Each table has the same primary key, and columns. I am trying to copy rows from one dataset to another, based on an event from my application.
1
by: GaryDean | last post by:
We have been developing all of our .net applications on 32 bit windows using 32 bit SQL Server. We are being asked to now deploy to servers running 64bit windows and 64bit SQL Server. Are there...
0
by: Anil Gupte | last post by:
The documentation says that LoadDataRow updates or inserts based upon whether the row exists or not. It does not say so in the documentation, but I figured the only way for it to know that is for...
3
by: eschneider | last post by:
Just some common issues with WS: Using custom objects: When objects change, seems you are always fixing some issue. Update references, which sometimes does not work. Deployment: Weird errors...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
0
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...
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.