|
-
Mar 24th, 2010, 04:28 PM
#1
Thread Starter
Lively Member
Listbox problem, information to textboxes...
I'm selecting a customer from a listbox of surnames...
I need to address to display, and the date arrived back...
Can't get anything to go into the textboxes, if dr.hasrows is showing up as none I think... not sure how to go about remedey"ing" it though...
Listbox Code:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim ConnectionString As String
Dim SQLString As String
Dim cmd As System.Data.OleDb.OleDbCommand
Dim conn As System.Data.OleDb.OleDbConnection
Dim dr As System.Data.OleDb.OleDbDataReader
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data "
ConnectionString += "Source=" & "Opticians.accdb "
conn = New System.Data.OleDb.OleDbConnection(ConnectionString)
AddressTextBox.Text = ListBox1.Text 'Gives the AddressTextBox the value that we click in the ListBox
SQLString = "SELECT * FROM CustomerTable " ' Selects all from CustomerTable
SQLString += "INNER JOIN SpectacleSalesTable ON CustomerTable.CustomerID = SpectacleSalesTable.CustomerID " 'Bring EyeTestTable in, using the records where the CustomerID matches up in both tables
SQLString += "Where '" & AddressTextBox.Text & "'" 'If the value that we clicked in the listbox, matches the surname it will try to connect
SQLString += "= Surname"
Try
conn.Open()
If ConnectionState.Open.ToString = "Open" Then
cmd = New System.Data.OleDb.OleDbCommand(SQLString, conn)
dr = cmd.ExecuteReader()
If dr.HasRows Then
dr.Read()
If Not IsDBNull(dr.Item("SpecSalesTable.FrameID")) Then
DepositTextBox.Text = dr.Item("SpecSalesTable.FrameID").ToString 'Adds the CustomerID to the CustomerIDTextBox
End If
If Not IsDBNull(dr.Item("SpecSalesTable.DateReceived")) Then
DateReceivedTextBox.Text = dr.Item("SpecSalesTable.DateReceived").ToString 'Adds the EyeTestID to the EyeTestIDTextBox
End If
If Not IsDBNull(dr.Item("CustomerTable.Street")) Then
AddressTextBox.Text = dr.Item("CustomerTable.Street").ToString 'Adds the Street to the AddressTextBox
End If
If Not IsDBNull(dr.Item("CustomerTable.Town")) Then
Address2TextBox.Text = dr.Item("CustomerTable.Town").ToString 'Adds the Town to the Address2TextBox
End If
If Not IsDBNull(dr.Item("CustomerTable.County")) Then
Address3TextBox.Text = dr.Item("CustomerTable.County").ToString 'Adds the County to the Address3TextBox
End If
End If
End If
Catch ex As Exception
End Try
End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|