hello,
i'm new programming ado.net and msde
i have the following problem:
when cmgegevens.addnew is called the binded trextboxes don't clear?
I can edit records, but when i'm trying to add a new one , i get the
following error:
column 'id' is read only .
But when i look at contacts table a new id is created but the fields i
filled in are empty (null) in the database
i have form (contacts entry/edit)
declarations:
Private daPostcode As SqlDataAdapter
Private dsPostcode As New DataSet
Private command As SqlCommand
Private WithEvents da As SqlDataAdapter
Private dsGegevens As New DataSet
Private cmGegevens As CurrencyManager
Private cbGegevens As SqlCommandBuilder
Private dv As DataView
Private boolStartup As Boolean = True
formload:
command = New SqlCommand("select * from dat_contacten", cn)
da = New SqlDataAdapter(command)
da.Fill(dsGegevens, "gegevens")
da.FillSchema(dsGegevens, SchemaType.Source, "gegevens")
dsGegevens.Tables("gegevens").Columns("id").AutoIn crementSeed = -1
dsGegevens.Tables("gegevens").Columns("id").AutoIn crementStep = -1
dv = dsGegevens.Tables("gegevens").DefaultView
cmGegevens = CType(Me.BindingContext(dv), CurrencyManager)
' cmGegevens.Position = 0
Call koppel() 'add some databindings
cbGegevens = New SqlCommandBuilder(da)
btnnew.click:
cmGegevens.AddNew()
Private Sub koppel()
txtBedrijf.DataBindings.Add(New Binding("text",
dsGegevens.Tables("gegevens"), "bedrijf"))
txtVoornaam.DataBindings.Add(New Binding("text",
dsGegevens.Tables("gegevens"), "voornaam"))
txtNaam.DataBindings.Add(New Binding("text", dsGegevens.Tables("gegevens"),
"naam"))
txtAdres.DataBindings.Add(New Binding("text", dsGegevens.Tables("gegevens"),
"adres"))
txtpostcode.DataBindings.Add(New Binding("text",
dsGegevens.Tables("gegevens"), "postcode"))
txtTelPrive.DataBindings.Add(New Binding("text",
dsGegevens.Tables("gegevens"), "tel_prive"))
End Sub
save button :
Try
cmGegevens.EndCurrentEdit()
da.Update(dsGegevens.Tables("gegevens"))
Catch ex As Exception
MessageBox.Show(ex.Message & vbCrLf & ex.Source & vbCrLf & ex.StackTrace)
End Try
da.rowupdated event:
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 @@IDENTITY", cn)
e.Row("id") = CType(cmdnieuwnr.ExecuteScalar, Integer)
e.Row.AcceptChanges()
End If
End sub