473,473 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DataSet update issuse

I am fetching data in DataSet - myDataSet, from a remote database using a
Web Service in my VB.NET client..Once I fetch it I store the data in XML
file (myXMLFile) using the WriteXML method of the myDataSet. The connection
to the Web Service is closed at this point.

I update this XML file in my application, and when I am ready to send the
data back, I load the XML file back to a DataSet - mySendDataSet, using
ReadXML method.

Now I send this mySendDataSet back to the Web Service that has to update the
remote database. I am having problems in updating the data back into the
database, using the WebService.

<WebMethod(Description:="Update")> Public Function SendDetails(ByVal
mySendDataSet As DataSet) As String

Dim myError As String
Dim mySQLQuery As String

Dim myConnection As New SqlClient.SqlConnection

Dim Id As Integer

Dim Server As String
Dim Database As String
Dim UID As String
Dim Password As String

Dim ConnectString As String

Try

Server =
System.Configuration.ConfigurationSettings.AppSett ings.Get("Server")
Database =
System.Configuration.ConfigurationSettings.AppSett ings.Get("Database")
UID =
System.Configuration.ConfigurationSettings.AppSett ings.Get("SqlUser")
Password =
System.Configuration.ConfigurationSettings.AppSett ings.Get("SqlPassword")

ConnectString = "Persist Security Info=False; Server=" & Server
& _
";Connect Timeout=30;database=" & Database & _
";User ID=" & UID & ";Pwd=" & Password & ";"

myConnection.ConnectionString = ConnectString
myConnection.Open()

Dim myCommand As New SqlClient.SqlCommand

Id = mySendDataSet.Tables(0).Rows(0).Item("ID")

'Delete the row first
mySQLQuery = "delete from myTable "
mySQLQuery = mySQLQuery & "where ID = " & Id

With myCommand
.Connection = myConnection
.CommandText = mySQLQuery
End With

myCommand.ExecuteNonQuery()

''Now insert the new row
mySQLQuery = "select * from myTable "
mySQLQuery = mySQLQuery & "where ID = " & Id

Dim myDataAdapter As New SqlClient.SqlDataAdapter(mySQLQuery,
myConnection)
' Ensure that the primary key is set correctly.
Dim myDataSet As New DataSet

' Fill the DataTable.
myDataAdapter.Fill(myDataSet, "myTable")
myDataSet = mySendDataSet

' Create an auxiliary CommandBuilder object for this
DataAdapter.
Dim cmdBuilder As New SqlClient.SqlCommandBuilder(myDataAdapter)

' Use it to generate the three xxxCommand objects.
'Update Here now...
myDataAdapter.InsertCommand = cmdBuilder.GetInsertCommand
myDataAdapter.DeleteCommand = cmdBuilder.GetDeleteCommand
myDataAdapter.UpdateCommand = cmdBuilder.GetUpdateCommand

myDataAdapter.Update(myDataSet, "myTable")

SendDetails = ""
myConnection.Close()

Catch myex As Exception

myError = myex.ToString
SendDetails = myError
myConnection.Close()

End Try

Do I have to do this way, I mean delete, then use the command builder
everytime. Because if I try to do without the delete, The update method
inserts the row, rather than updating. I have a index on ID column in the
database for the table. Also I am not able to use transactions, so I can
rollback the changes, if there is any issues. Can anybody suggest a
efficient way of updating the data back, or correct any mistakes I have
made.

Note: This dataset being used refers to always only one table in the
database and will have only one row to update at a time. Due to my
application restrictions, I will have to work in this disconnected fashion
and one record at a time. We are not dealing with a large amount of data,
just maybe 100 records at a time maximum.

Thanks a lot for helping
VJ
Nov 20 '05 #1
0 4903

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

Similar topics

6
by: Babu Mannaravalappil | last post by:
Can somebody please help me figure out why the following method exceptions out? Execution at the line marked with ********** hangs for about 15 seconds and then I get an error that says an...
2
by: Mojtaba Faridzad | last post by:
Hi, Please check these lines: DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet, "mytable"); DataRow row; row = dataSet.Tables.Rows; row.BeginEdit(); row = "555";
15
by: JIM.H. | last post by:
Hello, Can I send a dataset as a parameter into stored procedure and import data to a table in the stored procedure? Thanks, Jim.
4
by: jay | last post by:
I am using the dataset object to add a row to a sql server database in vb.net code, as follows: dim drow as DataRow dim cmdBld as new SqlCommandBuilder(mySqlDataAdapter) ds.tables(0).NewRow()...
9
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from...
7
by: Dan Sikorsky | last post by:
How do you iterate thru a dataset to change money fields to a different value? Here's what I have. My dataset is filled directly from a stored procedure. ' Create Instance of Connection and...
12
by: Graham Blandford | last post by:
Hi all, Would someone be able to tell me the most 'graceful' way of removing unwanted rows from a dataset based on a condition prior to update? OR, resetting the rows all to unchanged after they...
4
by: Peter Proost | last post by:
Hello group, what would be the best way to do the next thing: I've got a grid form with about 15000 records, when I double click a row a detail form is opened and the user can modify and save...
17
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only...
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
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
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.