Solved

DLOOKUP Equivalent

Posted on 2014-04-07
5
170 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
  • 2
  • 2
5 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
Comment Utility
Thank you!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now