-
Sep 23rd, 2010, 06:24 AM
#1
Thread Starter
New Member
[RESOLVED] ExecuteNonQuery keep overwrite values
Below are a part of my coding for my system. This works fine if I only insert/update/delete one row only. But if there are more than one rows in rowstate.Modified, the ExecuteNonQuery() will overwrite the previous value and just insert/update/delete the last row that the user input only. May I know what's wrong with my coding?? How can i prevent the ExecuteNonQuery() for overwrite the values?? Or is there any others way to let user insert/update/delete values at one time??
Code:
Dim rowChanged As Integer = dsEmp.Tables(0).GetChanges(DataRowState.Modified).Rows.Count
If rowChanged > 0 Then
Dim rows As DataRow
For Each rows In dsEmp.Tables(0).GetChanges(DataRowState.Modified).Rows
da.UpdateCommand.ExecuteNonQuery()
da.UpdateCommand.Parameters.Clear()
Next
End If
I really need your help and thanks for your help as well...
-
Sep 23rd, 2010, 06:47 AM
#2
Re: ExecuteNonQuery keep overwrite values
Post your SQL !!
Are you changing your SQL statement with each row you visit or does it remain static ?
Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you
-
Sep 23rd, 2010, 06:54 AM
#3
Thread Starter
New Member
Re: ExecuteNonQuery keep overwrite values
Hi, thanks for the reply first.
I am using stored procedure for executeNonQuery...
Code:
Dim deleteCommand As SqlCommand = New SqlCommand()
deleteCommand.Connection = New SqlConnection(strConn)
deleteCommand.Connection.Open()
deleteCommand.CommandType = CommandType.StoredProcedure
deleteCommand.CommandText = "dbo.Search_And_Delete_Employee"
Dim param As SqlParameter
param = deleteCommand.Parameters.Add("@EmpNo", SqlDbType.Int)
param.Direction = ParameterDirection.Input
param.Value = Me.txtEmpNo.Text
param.SourceVersion = DataRowVersion.Original
-
Sep 23rd, 2010, 08:06 AM
#4
Re: ExecuteNonQuery keep overwrite values
Don't use ExecuteNonQuery. If you have a DataTable, use a DataAdapter. You presumably used a DataAdapter to Fill the DataTable in the first place. If you didn't, you should. You then use the same DataAdapter to Update the database with the changes. Otherwise you're just making things more difficult for no gain. Follow the CodeBank link in my signature and check out my Retrieving & Saving Data thread for some relevant ADO.NET code examples.
-
Oct 1st, 2010, 06:13 AM
#5
Thread Starter
New Member
Re: ExecuteNonQuery keep overwrite values
ya, jmcilhinney you are correct and I solved it using DataAdapter also...
thanks everyone...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|