ReportsNerd
Active member
- Joined
- Nov 24, 2012
- Messages
- 31
- Programming Experience
- 3-5
Hi, I have been using a code example I found to search the access db and populate 3 text boxes on my form, but it does not appear to be working correctly. This code is returning the wrong record Im searching on. Not sure why. the item mappings are good with the text boxes, as they appear to be mapping to the fields in the database correctly. I honestly dont understand this loop construct (Btn_Seek) on the dataset and I think it may be wrong. Help appreciated. Thanks.
Public Class Menu
Dim dbProvider As String
Dim dbSource As String
'Dim con As New OleDb.OleDbConnection
Dim Sql As String = "SELECT * FROM DEBTOR"
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim i As Integer
Dim len As Integer
Dim ind As Integer = 0
Dim arrNumbers() As String
Dim no As Integer
Private Sub Menu_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
'dbSource = " C:\Users\Lynne\documents\visual studio 2010\Projects\DT\DT\TestDB1.accdb "
'con.ConnectionString = dbProvider & dbSource
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Users\Lynne\documents\visual studio 2010\Projects\DT\DT\TestDB1.accdb'")
con.Open()
da = New OleDb.OleDbDataAdapter(Sql, con)
da.Fill(ds, "Debtors")
len = da.Fill(ds, "Debtors")
End Sub
Private Sub BtnSeek_Click(sender As System.Object, e As System.EventArgs) Handles BtnSeek.Click
Dim sql1 = InputBox("Name:", "Search", "Anderson")
Dim no As Integer
Dim found As Boolean = False
For no = 0 To len - 1
If ds.Tables("Debtors").Rows(no).Item(2).ToString.ToLower = sql1.ToString.ToLower Then
i = no
nav()
found = True
End If
Next
If (found = False) Then
MsgBox("Search Not Found")
End If
End Sub
Private Sub nav()
txtName1.Text = ds.Tables("Debtors").Rows(1).Item(2)
txtAddr1.Text = ds.Tables("Debtors").Rows(1).Item(4)
txtAddr2.Text = ds.Tables("Debtors").Rows(1).Item(5)
End Sub
Public Class Menu
Dim dbProvider As String
Dim dbSource As String
'Dim con As New OleDb.OleDbConnection
Dim Sql As String = "SELECT * FROM DEBTOR"
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim i As Integer
Dim len As Integer
Dim ind As Integer = 0
Dim arrNumbers() As String
Dim no As Integer
Private Sub Menu_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
'dbSource = " C:\Users\Lynne\documents\visual studio 2010\Projects\DT\DT\TestDB1.accdb "
'con.ConnectionString = dbProvider & dbSource
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Users\Lynne\documents\visual studio 2010\Projects\DT\DT\TestDB1.accdb'")
con.Open()
da = New OleDb.OleDbDataAdapter(Sql, con)
da.Fill(ds, "Debtors")
len = da.Fill(ds, "Debtors")
End Sub
Private Sub BtnSeek_Click(sender As System.Object, e As System.EventArgs) Handles BtnSeek.Click
Dim sql1 = InputBox("Name:", "Search", "Anderson")
Dim no As Integer
Dim found As Boolean = False
For no = 0 To len - 1
If ds.Tables("Debtors").Rows(no).Item(2).ToString.ToLower = sql1.ToString.ToLower Then
i = no
nav()
found = True
End If
Next
If (found = False) Then
MsgBox("Search Not Found")
End If
End Sub
Private Sub nav()
txtName1.Text = ds.Tables("Debtors").Rows(1).Item(2)
txtAddr1.Text = ds.Tables("Debtors").Rows(1).Item(4)
txtAddr2.Text = ds.Tables("Debtors").Rows(1).Item(5)
End Sub