Click here to Skip to main content
15,889,595 members
Home / Discussions / Database
   

Database

 
GeneralDummies guide to SQL Pin
Michael P Butler15-Apr-03 23:14
Michael P Butler15-Apr-03 23:14 
GeneralRe: Dummies guide to SQL Pin
perlmunger16-Apr-03 5:44
perlmunger16-Apr-03 5:44 
Generalfield=field+', ' in SQL Pin
stefan b15-Apr-03 23:08
stefan b15-Apr-03 23:08 
GeneralRe: field=field+', ' in SQL Pin
Jeremy Oldham16-Apr-03 2:29
Jeremy Oldham16-Apr-03 2:29 
GeneralRe: field=field+', ' in SQL Pin
stefan b16-Apr-03 18:47
stefan b16-Apr-03 18:47 
GeneralSQL 2000 Backup to SQL 7 Backup Pin
Paul Watson15-Apr-03 22:10
sitebuilderPaul Watson15-Apr-03 22:10 
GeneralRe: SQL 2000 Backup to SQL 7 Backup Pin
Paul Watson15-Apr-03 22:57
sitebuilderPaul Watson15-Apr-03 22:57 
GeneralUpdating Multiple records through Storedprocedure and getting event notifications Pin
Mairaj Zeb15-Apr-03 20:42
Mairaj Zeb15-Apr-03 20:42 
Hi I am using fallowing table, storedprocedure, function and event handlers.
My problem is that I am abled to update one row successfully only.
If there are rows more than one that satisfy the matching criteria (i-e status=1 in this case, let 9 rows) then
I get the fallowing Error Message:-
"Concurrency Violation : the updateCommand affected 0 records"

What should I do to avoid this Error?

My task was to run a storedprocedure and get the description of
updated rows though event handler but I am doing it for one only,
how multiple rows can be updated in my situation?
What am I doing wrong?

Regards
Mairaj

'////////////
Table1 :-
Column Type
---------------------------
id Auto-Number
Description varchar(50)
satus bit


'/////////////////// Storedprocedure:-
CREATE PROCEDURE dbo.[Test_Update]
AS
UPDATE Table1 SET status = 0, Description = "UpDate test"
WHERE status=1;
GO



'////////// function :-
Public Function Excecute_Test_Update()

Dim MyTrans As SqlTransaction
Dim strConnString As String = "data source=(local);initial catalog=" & "Test" & ";uid=sa;password=;"
Dim connDB As New SqlClient.SqlConnection(strConnString)

Dim da As New SqlClient.SqlDataAdapter()
Dim ds As New DataSet()
Dim dtDB As DataTable

Try
connDB.Open()

Dim cmdDB2 As New SqlClient.SqlCommand()

cmdDB2.CommandType = CommandType.Text
cmdDB2.CommandText = "SELECT status, Description, Id from Table1"
cmdDB2.Connection = connDB


da.SelectCommand = cmdDB2
da.Fill(ds, "Table1")
connDB.Close()
dtDB = ds.Tables("Table1")

Dim strExpr As String
strExpr = "status" & " = " & 1
Dim foundRows() As DataRow
' Use the Select method to find all rows matching the filter.
foundRows = dtDB.Select(strExpr)

da.UpdateCommand = New SqlCommand("Test_Update")
da.UpdateCommand.CommandType = CommandType.StoredProcedure
da.UpdateCommand.Connection = connDB

Dim Len As Integer = foundRows.Length - 1
Dim i As Integer

For i = 0 To Len
foundRows(i)("status") = 0
foundRows(i)("Descrition") = "UpDate test"
Next


MsgBox("Updated count:" & dtDB.Select(Nothing, Nothing, DataViewRowState.ModifiedCurrent).Length)

connDB.Open()

AddHandler dtDB.RowChanged, New DataRowChangeEventHandler(AddressOf Row_Changed)
AddHandler da.RowUpdated, AddressOf OnRowUpdated

MyTrans = connDB.BeginTransaction()
da.UpdateCommand.Transaction = MyTrans
da.Update(ds, "Table1")

MyTrans.Commit()

Catch exp As Exception

MyTrans.Rollback()
MsgBox("Exception: " & exp.Message)
End Try

RemoveHandler dtDB.RowChanged, AddressOf Row_Changed
RemoveHandler da.RowUpdated, AddressOf OnRowUpdated


MyTrans.Dispose()
connDB.Close()


End Function

'///////////// handlers :-

' handler for rowchanged event
Private Sub Row_Changed(ByVal sender As Object, ByVal e As DataRowChangeEventArgs)

MsgBox("row changed")

End Sub

' handler for RowUpdated event
Protected Sub OnRowUpdated(ByVal sender As Object, ByVal e As System.Data.SqlClient.SqlRowUpdatedEventArgs)
MsgBox("Id " & e.Row("Id").ToString() & " Description " & e.Row("Description").ToString())
End Sub 'OnRowUpdated



Generaldata mining Pin
devvvy15-Apr-03 16:58
devvvy15-Apr-03 16:58 
GeneralSQL data to create directories Pin
gman4415-Apr-03 4:41
gman4415-Apr-03 4:41 
GeneralRe: SQL data to create directories Pin
Richard Deeming15-Apr-03 6:51
mveRichard Deeming15-Apr-03 6:51 
GeneralRe: SQL data to create directories Pin
si_6917-Apr-03 5:46
si_6917-Apr-03 5:46 
Generalreading a single record from SQL Pin
gollnick15-Apr-03 0:47
gollnick15-Apr-03 0:47 
GeneralRe: reading a single record from SQL Pin
perlmunger16-Apr-03 5:39
perlmunger16-Apr-03 5:39 
QuestionMS Access & BatchUpdate throw ADO ? Pin
rosen14-Apr-03 3:50
rosen14-Apr-03 3:50 
Generalsearch syntax problem Pin
ylaine14-Apr-03 1:09
ylaine14-Apr-03 1:09 
GeneralDataViewManager, Rowfilters and Child Filtering Pin
xpurt14-Apr-03 0:44
xpurt14-Apr-03 0:44 
GeneralDynamic SQL with in a stored procedure Pin
Venkatraman13-Apr-03 17:56
Venkatraman13-Apr-03 17:56 
GeneralPersonal Sql Server Pin
Steve McLenithan13-Apr-03 9:14
Steve McLenithan13-Apr-03 9:14 
GeneralRe: Personal Sql Server Pin
perlmunger16-Apr-03 6:01
perlmunger16-Apr-03 6:01 
GeneralRe: Personal Sql Server Pin
Steve McLenithan16-Apr-03 6:15
Steve McLenithan16-Apr-03 6:15 
Generalupdating 2 tables containing same value Pin
ylaine11-Apr-03 6:52
ylaine11-Apr-03 6:52 
GeneralRe: updating 2 tables containing same value Pin
Ixpah11-Apr-03 7:04
Ixpah11-Apr-03 7:04 
GeneralRe: updating 2 tables containing same value Pin
Ray Cassick11-Apr-03 8:47
Ray Cassick11-Apr-03 8:47 
GeneralADO.net connect to a remote access database Pin
Crossroad10-Apr-03 9:35
Crossroad10-Apr-03 9:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.