Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DLOOKUP Equivalent

Posted on 2014-04-07
5
Medium Priority
?
194 Views
Last Modified: 2014-04-09
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
Comment
Question by:russell12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 39984861
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
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 39985151
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
 
LVL 2

Author Comment

by:russell12
ID: 39985764
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39985779
>>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
 
LVL 2

Author Closing Comment

by:russell12
ID: 39988719
Thank you!!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question