|
-
Aug 30th, 2012, 08:29 AM
#1
Thread Starter
New Member
Search only first 8 chars of a column in database
Hey Guys,
Like usual, I tried searching but couldn't find anything specific to this problem I'm trying to fix.
I have a program that is reading a field from an Access database and if the field matches then it returns the second column in the database. However, the field that it is trying to match/lookup in the database is not always in the same format as the one that is input in the program.
Example:
Program: Field to lookup/match in database is 20092109
Database: The lookup column may have records in the same format, 8 characters long, or may have records with 11 characters long.
I want to be able to do a lookup in the database so that it is only searching the first 8 characters of the lookup column. So that if the record in the column is 11 characters long, only take the first 8 characters and see if it matches the field in the program.
What I have now:
Code:
Dim InvoiceNumber As String
Dim strSearchInvoice As String
strSearchInvoice = "Select * from TrackingInfo"
acscmd = New OleDbCommand(strSearchInvoice, acsconn)
acsdr = acscmd.ExecuteReader
While acsdr.Read
If acsdr(1).ToString = InvoiceNumber Then
lblTrackingNum.Text = acsdr(7)
End If
End While
acsdr.Close()
InvoiceNumber is always 8 characters long in the program. I need to lookup InvoiceNumber in the second column of my "TrackingInfo" database but only search the first 8 characters of that column. If a match is found, return value in another column and insert in lblTrackingNum.text.
I am still fairly new to the VB environment but I am willing to learn and take pointers. Any help would be greatly appreciated as I have used this forum for a lot of coding help but just recently decided to register.
Thank you.
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
|