G
Guest
I have a Windows form with textboxes, labels, comboboxes, and a listbox. I bind the database fields to those objects and would like the user to be able to click through them (forward, back, first, last). The navigation buttons are not working. I commented out the combobox code b/c I read somewhere that could be causing the problem. That didn't work. What am I doing wrong. Thanks.
Private Sub btnGetRecords_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetRecords.Click
If cboDept.SelectedIndex = 0 Then
MessageBox.Show("You must select an area.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
cboDept.Focus()
Else
Try
sb.Append("SELECT e.eqnum, nvl(purpose, ' ') AS purpose,")
sb.Append(" NVL(theory_of_operation,' ') AS theory_of_operation,")
sb.Append(" NVL(similar_devices, ' ') AS similar_devices,")
sb.Append(" NVL(level_nbr, 1) As level_nbr, l.description AS unit_op,")
sb.Append(" nvl(me.description, ' ') AS description, e.tagged")
sb.Append(" FROM dbo.th_equipment e, dbo.equipment@MAXLDA_P me, ")
sb.Append("dbo.locations@MAXLDA_P l ")
sb.Append("WHERE me.location LIKE '%")
sb.Append(CType(cboDept.SelectedItem, ItemData).Key)
sb.Append("%' AND ")
sb.Append("SubStr(me.location,1,5) = l.location AND ")
sb.Append(" me.eqnum=e.eqnum")
sb.Append(" ORDER BY e.eqnum")
da.SelectCommand.CommandText = sb.ToString()
da.Fill(ds, "equipment")
sb.Remove(0, sb.Length)
sb.Append("SELECT eqnum, issue_id FROM dbo.th_equipment_issue")
Dim cmdEqIssues As New OleDb.OleDbCommand(sb.ToString, conn)
Dim daEqIssues As New OleDb.OleDbDataAdapter(cmdEqIssues)
daEqIssues.Fill(ds, "equipment_issues")
sb.Remove(0, sb.Length)
sb.Append("SELECT issue_id, description FROM dbo.th_issue ")
sb.Append("ORDER BY description")
Dim cmdIssues As New OleDb.OleDbCommand(sb.ToString(), conn)
Dim daIssues As New OleDb.OleDbDataAdapter(cmdIssues)
daIssues.Fill(ds, "issues")
Dim equip_issue_rel As New DataRelation("eq_issue_rel", ds.Tables(0).Columns("eqnum"), ds.Tables(1).Columns("eqnum"))
ds.Relations.Add(equip_issue_rel)
Dim issue_rel As New DataRelation("is_rel", ds.Tables(2).Columns("issue_id"), ds.Tables(1).Columns("issue_id"))
ds.Relations.Add(issue_rel)
lbSelectedIssues.DataSource = ds.Tables("issues")
lbSelectedIssues.DisplayMember = ds.Tables("issues").Columns(1).ColumnName
lbSelectedIssues.ValueMember = ds.Tables("issues").Columns(0).ColumnName
lbSelectedIssues.DataBindings.Add("SelectedValue", ds.Tables("equipment_issues"), "issue_id")
txtPurpose.DataBindings.Add("Text", ds.Tables("equipment"), "purpose")
lblEQNUM.DataBindings.Add("Text", ds.Tables("equipment"), "eqnum")
lblUnitOp.DataBindings.Add("Text", ds.Tables("equipment"), "unit_op")
lblDescription.DataBindings.Add("Text", ds.Tables("equipment"), "description")
txtTheoryOfOperation.DataBindings.Add("Text", ds.Tables("equipment"), "theory_of_operation")
txtSimilarDevices.DataBindings.Add("Text", ds.Tables("equipment"), "similar_devices")
' cboLevel.DataSource = ds.Tables("equipment")
' cboLevel.DisplayMember = "level_nbr"
' cboLevel.ValueMember = "level_nbr"
'cboLevel.DataBindings.Add("SelectedValue", ds.Tables("equipment"), "level_nbr")
' cboTagged.DataSource = ds.Tables("equipment")
' cboTagged.DisplayMember = "tagged"
' cboTagged.ValueMember = "tagged"
'cboTagged.DataBindings.Add("SelectedValue", ds.Tables("equipment"), "tagged")
eqBindingManagerBase = Me.BindingContext(ds, "equipment")
Catch ex As Exception
MessageBox.Show("Encountered error when getting records.", "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
eqBindingManagerBase.Position = eqBindingManagerBase.Count - 1
End Sub
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
eqBindingManagerBase.Position = 0
End Sub
Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
eqBindingManagerBase.Position -= 1
End Sub
Private Sub btnForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForward.Click
eqBindingManagerBase.Position += 1
End Sub
Private Sub btnGetRecords_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetRecords.Click
If cboDept.SelectedIndex = 0 Then
MessageBox.Show("You must select an area.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
cboDept.Focus()
Else
Try
sb.Append("SELECT e.eqnum, nvl(purpose, ' ') AS purpose,")
sb.Append(" NVL(theory_of_operation,' ') AS theory_of_operation,")
sb.Append(" NVL(similar_devices, ' ') AS similar_devices,")
sb.Append(" NVL(level_nbr, 1) As level_nbr, l.description AS unit_op,")
sb.Append(" nvl(me.description, ' ') AS description, e.tagged")
sb.Append(" FROM dbo.th_equipment e, dbo.equipment@MAXLDA_P me, ")
sb.Append("dbo.locations@MAXLDA_P l ")
sb.Append("WHERE me.location LIKE '%")
sb.Append(CType(cboDept.SelectedItem, ItemData).Key)
sb.Append("%' AND ")
sb.Append("SubStr(me.location,1,5) = l.location AND ")
sb.Append(" me.eqnum=e.eqnum")
sb.Append(" ORDER BY e.eqnum")
da.SelectCommand.CommandText = sb.ToString()
da.Fill(ds, "equipment")
sb.Remove(0, sb.Length)
sb.Append("SELECT eqnum, issue_id FROM dbo.th_equipment_issue")
Dim cmdEqIssues As New OleDb.OleDbCommand(sb.ToString, conn)
Dim daEqIssues As New OleDb.OleDbDataAdapter(cmdEqIssues)
daEqIssues.Fill(ds, "equipment_issues")
sb.Remove(0, sb.Length)
sb.Append("SELECT issue_id, description FROM dbo.th_issue ")
sb.Append("ORDER BY description")
Dim cmdIssues As New OleDb.OleDbCommand(sb.ToString(), conn)
Dim daIssues As New OleDb.OleDbDataAdapter(cmdIssues)
daIssues.Fill(ds, "issues")
Dim equip_issue_rel As New DataRelation("eq_issue_rel", ds.Tables(0).Columns("eqnum"), ds.Tables(1).Columns("eqnum"))
ds.Relations.Add(equip_issue_rel)
Dim issue_rel As New DataRelation("is_rel", ds.Tables(2).Columns("issue_id"), ds.Tables(1).Columns("issue_id"))
ds.Relations.Add(issue_rel)
lbSelectedIssues.DataSource = ds.Tables("issues")
lbSelectedIssues.DisplayMember = ds.Tables("issues").Columns(1).ColumnName
lbSelectedIssues.ValueMember = ds.Tables("issues").Columns(0).ColumnName
lbSelectedIssues.DataBindings.Add("SelectedValue", ds.Tables("equipment_issues"), "issue_id")
txtPurpose.DataBindings.Add("Text", ds.Tables("equipment"), "purpose")
lblEQNUM.DataBindings.Add("Text", ds.Tables("equipment"), "eqnum")
lblUnitOp.DataBindings.Add("Text", ds.Tables("equipment"), "unit_op")
lblDescription.DataBindings.Add("Text", ds.Tables("equipment"), "description")
txtTheoryOfOperation.DataBindings.Add("Text", ds.Tables("equipment"), "theory_of_operation")
txtSimilarDevices.DataBindings.Add("Text", ds.Tables("equipment"), "similar_devices")
' cboLevel.DataSource = ds.Tables("equipment")
' cboLevel.DisplayMember = "level_nbr"
' cboLevel.ValueMember = "level_nbr"
'cboLevel.DataBindings.Add("SelectedValue", ds.Tables("equipment"), "level_nbr")
' cboTagged.DataSource = ds.Tables("equipment")
' cboTagged.DisplayMember = "tagged"
' cboTagged.ValueMember = "tagged"
'cboTagged.DataBindings.Add("SelectedValue", ds.Tables("equipment"), "tagged")
eqBindingManagerBase = Me.BindingContext(ds, "equipment")
Catch ex As Exception
MessageBox.Show("Encountered error when getting records.", "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
eqBindingManagerBase.Position = eqBindingManagerBase.Count - 1
End Sub
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
eqBindingManagerBase.Position = 0
End Sub
Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
eqBindingManagerBase.Position -= 1
End Sub
Private Sub btnForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForward.Click
eqBindingManagerBase.Position += 1
End Sub