By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,032 Members | 1,183 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,032 IT Pros & Developers. It's quick & easy.

Error getting Identity Value using StronglyTyped Dataset

P: n/a
When I do this using UnStrongly Type, Everything works fine. I get the
Identity value

Private Sub formUnit_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

AddHandler daUnitLocations.RowUpdated, AddressOf HandleRowUpdated

Dim dt As DataTable = New DataTable
daUnitLocations.Fill(dt)
Dim aROw As DataRow = dt.NewRow
aROw("InventoryID") = 3
dt.Rows.Add(aROw)
daUnitLocations.Update(dt)
End Sub

Private Sub HandleRowUpdated(ByVal sender As Object, ByVal e As
System.Data.SqlClient.SqlRowUpdatedEventArgs)
Try
Dim cmGetIdentity As New SqlClient.SqlCommand("Select
@@Identity", Me.SqlConnection1)
If e.StatementType = StatementType.Insert Then
e.Row("UnitID") = CType(cmGetIdentity.ExecuteScalar,
Integer)
e.Row.AcceptChanges()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

----------------------------------------
But when the do the same using stronglyTyped dataset then I get a Readonly
Error in line e.Row("UnitID") = CType(cmGetIdentity.ExecuteScalar, Integer)
..

Private Sub formUnit_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
daUnitLocations.Fill(DataSet11)
Dim aROw As DataRow = DataSet11.UnitLocations.NewRow
aROw("InventoryID") = 3
DataSet11.UnitLocations.Rows.Add(aROw)
daUnitLocations.Update(DataSet11)
End Sub
What am I missing. Please advise.
Thanks in advance.
Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.