Hello,
vb.net /MSDE question
I have a form to add a new record.When Save buttton is pushed,the
record is saved to the database,but i don't know how to
get the new id back in my dataset (instead of -1)
the rowupdated event more specific :
e.row("id") =.... throws an error : 'column 'id' is readonly'
I know id is readonly.but i in the past i used the same code(except
@@identity instead of ident_current)
with access databases and everthing worked fine.
here's the code i used
da = New SqlDataAdapter(command)
da.FillSchema(ds, SchemaType.Source, "gegevens")
ds.Tables("gegevens").Columns("id").AutoIncrementSeed = -1
ds.Tables("gegevens").Columns("id").AutoIncrementStep = -1
da.Fill(ds, "gegevens")
dv = ds.Tables("gegevens").DefaultView
cmb = New SqlCommandBuilder(da)
cm = CType(Me.BindingContext(dv), CurrencyManager)
Private Sub da_RowUpdated(ByVal sender As Object, ByVal e As
System.Data.SqlClient.SqlRowUpdatedEventArgs) Handles da.RowUpdated
If e.Status = UpdateStatus.Continue AndAlso (e.StatementType =
StatementType.Insert) Then
Dim cmdnieuwnr As New SqlCommand("SELECT
IDENT_CURRENT('dat_test')", cn)
e.Row("id") = CType(cmdnieuwnr.ExecuteScalar, Integer)
e.Row.AcceptChanges()
End I
End Sub
any help apreciated,looking for the answer for 2 days now
Kind regards,
Stefan