|
|
|
Usually in your application you use two different types of lookup query; the first one is for retrieving a page of records (or all records) to populate a pick list, the other one is to retrieve a single record, i.e. for decoding a code description while user is typing it in a textbox. So, if your queries are dynamically configured and are stored in a DB, you must duplicate the list of query statements. So you'll use in the first in the first situation a query like: |
In the other situation you'll use a query like: |
But you can use just one query structured in dual mode: |
When you want to populate a pick list you'll pass to the second parameter simply a 1 and all records will be retrieved. When you want to decode a single value, you must pass the code to the first parameter and a 0 to the second one. So, if all your queries use always one parameter to decode value, you can write a standard (dual) lookup routine like this: |
Click here to copy the following block | Dim lConn As ADODB.Connection Dim lCmd As ADODB.Command Dim lRs As ADODB.Recordset Dim lParAllRecords as Long Dim lParSingleRecord as Long
Set lConn = New ADODB.Connection lConn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial " _ & "Catalog=PUBS;Data Source=(local)" lConn.CursorLocation = adUseClient Set lCmd = New ADODB.Command Set lCmd.ActiveConnection = lConn lCmd.CommandText = txtStatement.Text
lParAllRecords = 1 lParSingleRecord = 0
lParAllRecords = 0 lParSingleRecord = "Germany"
lCmd.Parameters(0).Value = lParSingleRecord lCmd.Parameters(1).Value = lParAllRecords Set lRs = lCmd.Execute |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|