S
s cartner
Iv got a simple form on my pda which i use to add new records to the
dataset, the form contains combo boxes and text fields, no bound objects at
all. I can add new records to that dataset no problem. After i add a record
to the dataset, i want to add the new row/record to my SQL Server CE
database. i can add the first record no problem, its when i try to add
another record im getting an exception:Update error. From what i understand,
my code should add a new row to the database and NOT update it. The code is
below. *Note* everytime i add a record to the dataset, i insert it into the
database.
Thanks for your help
Dim NewRow As DataRow
NewRow = dsFindingsSub.Tables(0).NewRow
With NewRow
.Item("InsNo") = mlngInsNo
.Item("TreeID") = mlngTreeID
.Item("Finding") = Me.cboFindings.Text
.Item("Comments") = Me.txtComments.Text
.Item("Priority") = Me.cboPriorities.Text
End With
dsFindingsSub.Tables(0).Rows.Add(NewRow)
'dsFindingsSub.AcceptChanges()
Me.BindingContext(Me.dsFindingsSub.Tables(0)).Position =
dsFindingsSub.Tables(0).Rows.Count
Dim sqlFindingsSubAddCommand As New SqlServerCe.SqlCeCommand
Dim strFinding As String
Dim strComments As String
Dim strPriority As String
Dim lngInsNo As Long
Dim lngTreeID As Long
Dim strInsertSQL As String
lngInsNo = mlngInsNo
lngTreeID = mlngTreeID
strFinding = cboFindings.Text
strComments = txtComments.Text
strPriority = cboPriorities.Text
strInsertSQL = "INSERT INTO zsExpInspSub(InsNo, TreeID, Finding,
Comments, Priority) VALUES ("
strInsertSQL = strInsertSQL & "'" & lngInsNo & "', "
strInsertSQL = strInsertSQL & "'" & lngTreeID & "', "
strInsertSQL = strInsertSQL & "'" & strFinding & "', "
strInsertSQL = strInsertSQL & "'" & strComments & "', "
strInsertSQL = strInsertSQL & "'" & strPriority & "' "
strInsertSQL = strInsertSQL & ")"
sqlFindingsSubAddCommand = ssceconn.CreateCommand()
sqlFindingsSubAddCommand.CommandText = strInsertSQL
daFindingssub.InsertCommand = sqlFindingsSubAddCommand
daFindingssub.Update(dsFindingsSub, "zsExpInspSub")
dataset, the form contains combo boxes and text fields, no bound objects at
all. I can add new records to that dataset no problem. After i add a record
to the dataset, i want to add the new row/record to my SQL Server CE
database. i can add the first record no problem, its when i try to add
another record im getting an exception:Update error. From what i understand,
my code should add a new row to the database and NOT update it. The code is
below. *Note* everytime i add a record to the dataset, i insert it into the
database.
Thanks for your help
Dim NewRow As DataRow
NewRow = dsFindingsSub.Tables(0).NewRow
With NewRow
.Item("InsNo") = mlngInsNo
.Item("TreeID") = mlngTreeID
.Item("Finding") = Me.cboFindings.Text
.Item("Comments") = Me.txtComments.Text
.Item("Priority") = Me.cboPriorities.Text
End With
dsFindingsSub.Tables(0).Rows.Add(NewRow)
'dsFindingsSub.AcceptChanges()
Me.BindingContext(Me.dsFindingsSub.Tables(0)).Position =
dsFindingsSub.Tables(0).Rows.Count
Dim sqlFindingsSubAddCommand As New SqlServerCe.SqlCeCommand
Dim strFinding As String
Dim strComments As String
Dim strPriority As String
Dim lngInsNo As Long
Dim lngTreeID As Long
Dim strInsertSQL As String
lngInsNo = mlngInsNo
lngTreeID = mlngTreeID
strFinding = cboFindings.Text
strComments = txtComments.Text
strPriority = cboPriorities.Text
strInsertSQL = "INSERT INTO zsExpInspSub(InsNo, TreeID, Finding,
Comments, Priority) VALUES ("
strInsertSQL = strInsertSQL & "'" & lngInsNo & "', "
strInsertSQL = strInsertSQL & "'" & lngTreeID & "', "
strInsertSQL = strInsertSQL & "'" & strFinding & "', "
strInsertSQL = strInsertSQL & "'" & strComments & "', "
strInsertSQL = strInsertSQL & "'" & strPriority & "' "
strInsertSQL = strInsertSQL & ")"
sqlFindingsSubAddCommand = ssceconn.CreateCommand()
sqlFindingsSubAddCommand.CommandText = strInsertSQL
daFindingssub.InsertCommand = sqlFindingsSubAddCommand
daFindingssub.Update(dsFindingsSub, "zsExpInspSub")