Senin, 09 Februari 2009

Searching for fields

When you want to search for an item in a database, you don’t want to search through every byte in the file, so to cut the amount of searching needed, you only look at the selected field in the current record. So for a database with only three fields and you only want to look at one of those fields, you would do a search like this:

Lastrecord = Filelen (filetostoredata) / Len (Typename)

x = 1

Do

Get #1, x, Typename


If trim (ucase (Typename.ARTIST))=trim (ucase (txtARTIST.text)) then

… Do what’s needed to add to what you do when you found a

… variable

End if

x = x + 1

Loop while x <= Lastrecord

What the code above does is:

First you get the how many records there are in the Database file and initialise x as one, x is then the record number you currently want. (There is no record zero so that’s why it’s set to one).
Next set up a loop, to loop the number through each of the records.
When in the loop you retrieve the record numbered x.
Next because we set up a type we can get the information easily from the correct field in the record and then compare it to your search string, if a match is found you can do what ever you want with the result.
Lastly increment the current record number "x"
There are other ways in which to do this but this way you make sure that the whole file is searched and not one that exits when just one match is found, remember there may be more than one match found.

Example Database Project

The next section is a simple Database project for you to follow along with. It is based on what I said earlier about keeping your record collection ordered.



source: http://www.vbexplorer.com/VBExplorer/VBExplorer.asp



-----------------------------------------------

Related:


sqlserver2005-security
view information vb2005
write file in vb2005
Barcode-string-encoderVbnet
Changing-backgroundcolor
Trik finding google
Directly-filling control
Date-time format vb2008
Finding google rank
Domain checker phps cript
Foreign key sql2005
Create-insert-tableadapter
Check datagrid
Hapus error handling vb2008
Function2 vb2008