Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

DLOOKUP Equivalent

I am in the process of converting from ms access.  I have a code that looks at a database on txtreportedby.text_LostFocus  event.  It querys a db call Advisories.  The way the select statement is: SELECT Name from Advisory WHERE Name = '" +txtreportedby.text+ "'.  If the name is in the db, it will popup form "Advisories". The DLOOKUP I have from access is:

        'If no match is found do nothing
         If IsNull(DLookup("[name]", "Advisories", "[name]='" & Me![txtReportedBy] & "'")) Then
        Exit Sub
        End If

Open in new window

Any help would be greatly appreciated as I have quite a few DLOOKUP I am having to convert.  I have searched around and there is no place out there that comes close to the experts on here.  So thanks in advance!!  Also I am using VB.NET not C++.
0
russell12
Asked:
russell12
  • 2
  • 2
1 Solution
 
Fernando SotoCommented:
Well As you may know there is no equivalent function in Visual Basic .Net. You will need to access the database by A different means. You state in your question, "I am in the process of converting from ms access", to what type of database? In order to answer your question we will need to know this.
0
 
AndyAinscowCommented:
Basically you need to write your own DLOOKUP equivalent.  The one you have takes the field name, the table (or query) name and a where condition.  So your function would be something like this
DLOOKUP(fld, tbl, cond)
{
check things are passed in
string s = "SELECT " + fld + " FROM " + tbl + " WHERE " + cond
get the database opened or retrieve an existing connection
run the query against the database
store the contents of the returned field
close up and return what should be returned
}
0
 
russell12Author Commented:
We use access for a front end and use SQL Server for backend.  I was already thinking I was going to have use a select statement, but my question is, do I have to put the result in a textbox, or could I dim the variable?  I am not getting anything for a textbox, just if the name exist in advisories, open a form.  I hope this is making sense.  I use VB Studio 2013 Pro, using VB
0
 
AndyAinscowCommented:
>>do I have to put the result in a textbox, or could I dim the variable?

Either, whichever makes the most sense for using the retrieved value further in your app.
0
 
russell12Author Commented:
Thank you!!
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now