OK, that seemed to put the dataset position at the last existing
record, not at the new one, but at least it wasn't on the current
record. Taking out the -1 puts me at the new record.
Now I get a syntax error when I update the db. I was under the
impression the commandbuilder built the update query. Do I have to
build it manually, a/o manually supply the parameters? If it helps,
here's most of the code that's involved (the <x>module code is for a
different tab page):
Private Sub BindControls()
Try
txtQuestion.DataBindings.Add(New Binding("Text",
dsQuestion, "QS.QText"))
txtQuNum.DataBindings.Add(New Binding("Text", dsQuestion,
"QS.Q#"))
cboQuNum.DataSource = dsQuestion.Tables("QS")
cboQuNum.DisplayMember = "Q#"
dgModule.DataSource = dsModule
dgModule.DataMember = "[Mod List]"
Catch ex As Exception
MessageBox.Show(ex.Message, "Binding Controls")
End Try
End Sub
Private Sub GetData()
Try
CreateADOObjects()
FillTables() 'fill datsets
bmbQuestion = Me.BindingContext(dsQuestion, "QS")
bmbModule = Me.BindingContext(dsModule, "[Mod List]")
BindControls()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error Getting Data")
End Try
End Sub
Private Sub CreateADOObjects()
cn.ConnectionString = mstrFullPath
Try
cmdQuestion.Connection = cn
Dim strQuestionSelect As String
strQuestionSelect = "SELECT * FROM QS"
cmdQuestion.CommandText = strQuestionSelect
daQuestion.SelectCommand = cmdQuestion
cmdModule.Connection = cn
Dim strModuleSelect As String
strModuleSelect = "SELECT * FROM [Mod List]"
cmdModule.CommandText = strModuleSelect
daModule.SelectCommand = cmdModule
'Shouldn't this build the update, insert & delete
commands?
cbQuestion = New OleDbCommandBuilder(daQuestion)
cbModule = New OleDbCommandBuilder(daModule)
Catch ex As Exception
MessageBox.Show(ex.ToString, "Creating Objects")
Me.Close()
End Try
End Sub
Private Sub UpdateDB()
Try
With daQuestion
.Update(dsQuestion, "QS")
dsQuestion.Clear()
.Fill(dsQuestion, "QS")
End With
Catch ex As Exception
MessageBox.Show(ex.ToString & vbCrLf, "Error Updating
Database")
End Try
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnSave.Click
blnLoading = True
UpdateDB()
blnLoading = False
btnSave.Enabled = False
cboQuNum.Focus()
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnUpdate.Click
If ValidateData() Then
bmbQuestion.EndCurrentEdit()
If blnNewRow Then
cboQuNum.SelectedIndex = bmbQuestion.Count - 1
blnNewRow = False
End If
SetButtons(True)
btnSave.Enabled = True
cboQuNum.Focus()
End If
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
Try
bmbQuestion.AddNew()
BindingContext(dsQuestion, "QS").Position =
dsQuestion.Tables("QS").Rows.Count
SetButtons(True)
btnSave.Enabled = True
blnNewRow = True
txtQuestion.Clear()
txtQuNum.Clear()
txtQuNum.Focus()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error Adding Record")
End Try
End Sub
Private Sub cboQuNum_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cboQuNum.SelectedIndexChanged
If Not blnLoading Then
bmbQuestion.Position = cboQuNum.SelectedIndex
SetButtons(True)
btnSave.Enabled = dsQuestion.HasChanges
txtQuNum.Focus()
End If
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnDelete.Click
Dim ans As DialogResult
ans = MessageBox.Show("Delete question #: " & cboQuNum.Text &
"?", "Confirm Delete", MessageBoxButtons.YesNo,
MessageBoxIcon.Question)
If ans = DialogResult.Yes Then
dblOldNum = CDbl(txtQuNum.Text)
bmbQuestion.RemoveAt(bmbQuestion.Position)
cboQuNum.Focus()
Else
MessageBox.Show("Delete of question #: " & cboQuNum.Text &
" cancelled.", "Delete Cancelled")
End If
End Sub
|