Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I do the equivalent of a dlookup

Status
Not open for further replies.

captphan

Programmer
Jan 24, 2007
42
I am doing some work with my database on a web page using VB. I want o grab just the value of one column from a row I have the key for. In access and VBA I would use the dlookup function. How do I do this in SQL server.


I am glad I don't know it all because then I would be bored.
-Obie
 
SELECT YourColumnName FROM YourTable WHERE KeyColumn = YourKeyColumnValue.
 
This is where my lack of experience using these tools comes into play.

is it
Varaiblename = "SELECT YourColumnName FROM YourTable WHERE KeyColumn = YourKeyColumnValue"



I am glad I don't know it all because then I would be bored.
-Obie
 
To help make it a little clearer, remember that SQL Server is a database engine and not a tool. It comes with some tools for admins to use to administer the server and to write queries, but the engine itself is not a tool so to speak. The engine can be programmed against using T-SQL. The code I showed you is T-SQL. The code is designed to return a value. However, in order to use the value, you must use a tool to send the query code and receive the value back.

That being said, are you simply using Managment Studio as the query tool, or a programming language or something else? T-SQL has variables, but I'm not sure that is what you are after.
 
I am codin in vb.net

I am glad I don't know it all because then I would be bored.
-Obie
 
Then as a basic rundown, you need to create some System.Data.Sqlclient objects in your VB code to access the SQL Server database. You can use a SqlCommand object to send a T-SQL query to SQL Server, and what you might be looking for is the .ExecuteScalar function of the SqlCommand object to return the single value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top