J
Jason James
Hi all,
I am struggling to get around a data.readonlyexception issue with
my SQL database.
I have declared my dataadapter withevents and use the event
handler below to obtain the actual PK written to the DB. The
field name is iID. I am using SELECT @@IDENTITY to obtain
the ID of the last written field. This is all working fine.
However, when I get to the line that reads
e.row("iID") = id
the data.readonlyexcpetion is raised.
Private Sub myDaCountedItems_RowUpdated(ByVal sender As Object,
ByVal e As System.Data.SqlClient.SqlRowUpdatedEventArgs) Handles
myDaCountedItems.RowUpdated
If Not IsNothing(e.Errors) Then
Debug.WriteLineIf(myDebugSwitch.Enabled = True, e.Errors)
End If
Try
If e.Status = UpdateStatus.Continue AndAlso
e.StatementType = StatementType.Insert Then
Dim cmdGetIdentity As New SqlCommand("SELECT
@@IDENTITY", myConn)
Dim id As Int32 =
Convert.ToInt32(cmdGetIdentity.ExecuteScalar())
e.Row("iID") = id
Debug.WriteLine(e.Row("iID"))
e.Row.AcceptChanges()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
I have tried to call row.beginedit and row.endedit, but I still
get the exception. Any ideas what might be causing this? I
use the same technique for an Access DB and all it fine!
Many thanks,
Jason.
I am struggling to get around a data.readonlyexception issue with
my SQL database.
I have declared my dataadapter withevents and use the event
handler below to obtain the actual PK written to the DB. The
field name is iID. I am using SELECT @@IDENTITY to obtain
the ID of the last written field. This is all working fine.
However, when I get to the line that reads
e.row("iID") = id
the data.readonlyexcpetion is raised.
Private Sub myDaCountedItems_RowUpdated(ByVal sender As Object,
ByVal e As System.Data.SqlClient.SqlRowUpdatedEventArgs) Handles
myDaCountedItems.RowUpdated
If Not IsNothing(e.Errors) Then
Debug.WriteLineIf(myDebugSwitch.Enabled = True, e.Errors)
End If
Try
If e.Status = UpdateStatus.Continue AndAlso
e.StatementType = StatementType.Insert Then
Dim cmdGetIdentity As New SqlCommand("SELECT
@@IDENTITY", myConn)
Dim id As Int32 =
Convert.ToInt32(cmdGetIdentity.ExecuteScalar())
e.Row("iID") = id
Debug.WriteLine(e.Row("iID"))
e.Row.AcceptChanges()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
I have tried to call row.beginedit and row.endedit, but I still
get the exception. Any ideas what might be causing this? I
use the same technique for an Access DB and all it fine!
Many thanks,
Jason.