Hello,
I am currently using Visual Basic 2005 express edition with a MS Access database. I have made a "Contacts" Form, where the user will be able to enter a members surname and press an OK button, this then searches through the database and displays the results in the corresponding text boxes (ID, FirstName, LastName etc) of the searched member. I have used an SQL statement to search through the database, the problem I am having is filling the text boxes (ID, FirstName, LastName etc) with the correct member.
Below is my search code:
Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.Click
Dim inc As Integer
Dim maxrows As Integer
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\My Documents\Visual Studio 2005\Projects\BugReport\BugReport\Issues Database.MDB"
con.Open()
Dim str As String
str = "SELECT * FROM Contacts WHERE FirstName = '" & TextSearch.Text & "'"
da = New OleDb.OleDbDataAdapter(str, con)
da.Fill(ds, "Contacts")
con.Close()
ID.Text = ds.Tables("Contacts").Rows(0).Item(0)
FirstName.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(1) )
LastName.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(2) )
EmailAddress.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(3) )
Company.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(4) )
JobTitle.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(5) )
BusinessPhone.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(6) )
HomePhone.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(7) )
MobilePhone.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(8) )
FaxNumber.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(9) )
Address.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(10 ))
City.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(11 ))
StateProvince.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(12 ))
ZIPPostalCode.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(13 ))
CountryRegion.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(14 ))
WebPage.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(15 ))
Notes.Text = GetTextField(ds.Tables("Contacts").Rows(0).Item(16 ))
maxrows = ds.Tables("Contacts").Rows.Count
inc = 0
End Sub
Thanks in Advance