473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Dlookup function

Hi

Is there a dlookup function in vb.net like in access which returns a column
value from a table for a given criteria? If not, is there a sample I can
look at?

Thanks

Regards
Mar 9 '08 #1
7 10710
"John" <Jo**@nospam.infovis.co.ukwrote in
news:eA*************@TK2MSFTNGP02.phx.gbl:
Is there a dlookup function in vb.net like in access which returns a
column value from a table for a given criteria? If not, is there a
sample I can look at?
SELECT MyColumn FROM MyTable WHERE MyColumn = SOMEVALUE ;-)

..NET has several ways to achieve what you want depending on how you're
storing your data.

LINQ
ADO.NET database query
..Find Delegate (supported on some collections)
Dataset/DataView filters

--
sp**********@rogers.com (Do not e-mail)
Mar 9 '08 #2
What is a fast way to do this? Sorry, but too many answers is no answer.

Regards

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"John" <Jo**@nospam.infovis.co.ukwrote in
news:eA*************@TK2MSFTNGP02.phx.gbl:
>Is there a dlookup function in vb.net like in access which returns a
column value from a table for a given criteria? If not, is there a
sample I can look at?

SELECT MyColumn FROM MyTable WHERE MyColumn = SOMEVALUE ;-)

.NET has several ways to achieve what you want depending on how you're
storing your data.

LINQ
ADO.NET database query
.Find Delegate (supported on some collections)
Dataset/DataView filters

--
sp**********@rogers.com (Do not e-mail)

Mar 9 '08 #3
"John" <Jo**@nospam.infovis.co.ukwrote in news:ezmv58hgIHA.5160
@TK2MSFTNGP05.phx.gbl:
What is a fast way to do this? Sorry, but too many answers is no answer.
What's your data source?

If it's a database, use a SQL Query.
--
sp**********@rogers.com (Do not e-mail)
Mar 9 '08 #4
Will below do?

Thanks

Regards

Function DLookup(ByVal SearchFld As String, ByVal SearchTbl As String, ByVal
SearchCriteria As String) As Object
Dim Cmd As OleDb.OleDbCommand
Dim Reader As OleDb.OleDbDataReader
Dim Value As Object = DBNull.Value

DLookup = Nothing
Cmd = New OleDb.OleDbCommand("SELECT " & SearchFld & " FROM " & SearchTbl &
" WHERE " & SearchCriteria, DBConnection())
Reader = Cmd.ExecuteReader()
If Microsoft.VisualBasic.Left(SearchFld, 1) = "[" Then
SearchFld = Microsoft.VisualBasic.Right(SearchFld,
Microsoft.VisualBasic.Len(SearchFld) - 1)
End If
If Microsoft.VisualBasic.Right(SearchFld, 1) = "]" Then
SearchFld = Microsoft.VisualBasic.Left(SearchFld,
Microsoft.VisualBasic.Len(SearchFld) - 1)
End If
If (Reader.Read()) Then
Value = IIf(Reader.GetString(Reader.GetOrdinal(SearchFld)) Is Nothing, "",
Reader.GetString(Reader.GetOrdinal(SearchFld)))
End If
DLookup = Value

End Function

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"John" <Jo**@nospam.infovis.co.ukwrote in news:ezmv58hgIHA.5160
@TK2MSFTNGP05.phx.gbl:
>What is a fast way to do this? Sorry, but too many answers is no answer.

What's your data source?

If it's a database, use a SQL Query.
--
sp**********@rogers.com (Do not e-mail)

Mar 9 '08 #5
"John" <Jo**@nospam.infovis.co.ukwrote in
news:#u**************@TK2MSFTNGP06.phx.gbl:
DLookup = Nothing
Cmd = New OleDb.OleDbCommand("SELECT " & SearchFld & " FROM " &
SearchTbl & " WHERE " & SearchCriteria, DBConnection())
Reader = Cmd.ExecuteReader()
Yes, something like that will work.

Also look at ExecuteScalar command, it allows you to return one value.

You should also avoid doing string concatenation in your code because it
is ripe for SQL injection attacks. Instead you should use SQL Parameters
instead.

--
sp**********@rogers.com (Do not e-mail)
Mar 10 '08 #6
yah now we just need these for the other dozen domain aggregate
functions; thanks

seems to me like it should have shipped as built in functions

-aaron

On Mar 9, 1:34*pm, "John" <J...@nospam.infovis.co.ukwrote:
Will below do?

Thanks

Regards

Function DLookup(ByVal SearchFld As String, ByVal SearchTbl As String, ByVal
SearchCriteria As String) As Object
Dim Cmd As OleDb.OleDbCommand
Dim Reader As OleDb.OleDbDataReader
Dim Value As Object = DBNull.Value

DLookup = Nothing
Cmd = New OleDb.OleDbCommand("SELECT " & SearchFld & " FROM " & SearchTbl &
" WHERE " & SearchCriteria, DBConnection())
Reader = Cmd.ExecuteReader()
If Microsoft.VisualBasic.Left(SearchFld, 1) = "[" Then
SearchFld = Microsoft.VisualBasic.Right(SearchFld,
Microsoft.VisualBasic.Len(SearchFld) - 1)
End If
If Microsoft.VisualBasic.Right(SearchFld, 1) = "]" Then
SearchFld = Microsoft.VisualBasic.Left(SearchFld,
Microsoft.VisualBasic.Len(SearchFld) - 1)
End If
If (Reader.Read()) Then
Value = IIf(Reader.GetString(Reader.GetOrdinal(SearchFld)) Is Nothing, "",
Reader.GetString(Reader.GetOrdinal(SearchFld)))
End If
DLookup = Value

End Function

"Spam Catcher" <spamhoney...@rogers.comwrote in message

news:Xn**********************************@127.0.0. 1...
"John" <J...@nospam.infovis.co.ukwrote in news:ezmv58hgIHA.5160
@TK2MSFTNGP05.phx.gbl:
What is a fast way to do this? Sorry, but too many answers is no answer..
What's your data source?
If it's a database, use a SQL Query.
--
spamhoney...@rogers.com (Do not e-mail)- Hide quoted text -

- Show quoted text -
Mar 12 '08 #7
Bug Fix 1: Change the two GetString to GetValue.

<aa*********@gmail.comwrote in message
news:2a**********************************@i12g2000 prf.googlegroups.com...
yah now we just need these for the other dozen domain aggregate
functions; thanks

seems to me like it should have shipped as built in functions

-aaron

On Mar 9, 1:34 pm, "John" <J...@nospam.infovis.co.ukwrote:
Will below do?

Thanks

Regards

Function DLookup(ByVal SearchFld As String, ByVal SearchTbl As String,
ByVal
SearchCriteria As String) As Object
Dim Cmd As OleDb.OleDbCommand
Dim Reader As OleDb.OleDbDataReader
Dim Value As Object = DBNull.Value

DLookup = Nothing
Cmd = New OleDb.OleDbCommand("SELECT " & SearchFld & " FROM " & SearchTbl
&
" WHERE " & SearchCriteria, DBConnection())
Reader = Cmd.ExecuteReader()
If Microsoft.VisualBasic.Left(SearchFld, 1) = "[" Then
SearchFld = Microsoft.VisualBasic.Right(SearchFld,
Microsoft.VisualBasic.Len(SearchFld) - 1)
End If
If Microsoft.VisualBasic.Right(SearchFld, 1) = "]" Then
SearchFld = Microsoft.VisualBasic.Left(SearchFld,
Microsoft.VisualBasic.Len(SearchFld) - 1)
End If
If (Reader.Read()) Then
Value = IIf(Reader.GetString(Reader.GetOrdinal(SearchFld)) Is Nothing, "",
Reader.GetString(Reader.GetOrdinal(SearchFld)))
End If
DLookup = Value

End Function

"Spam Catcher" <spamhoney...@rogers.comwrote in message

news:Xn**********************************@127.0.0. 1...
"John" <J...@nospam.infovis.co.ukwrote in news:ezmv58hgIHA.5160
@TK2MSFTNGP05.phx.gbl:
What is a fast way to do this? Sorry, but too many answers is no
answer.
What's your data source?
If it's a database, use a SQL Query.
--
spamhoney...@rogers.com (Do not e-mail)- Hide quoted text -

- Show quoted text -

Mar 12 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: KLAU | last post by:
I have a field that retrieves information from an expression in a query. I have used a DLookup function to get the calculated field from the query. However, the relationship is 1-to-many so one...
4
by: David B | last post by:
I have a Public function which creates a back up copy of a back end. It works fine with the source path and source file as C:\folder\etc. I thought I would try to store the paths in a table so...
2
by: Ronny Sigo | last post by:
Hello all, I already put the same question, only now I have more to tell ... Although I used this code before in the same routine (only the fieldname of the table differs) ___ at this point in the...
1
by: Thelma Lubkin | last post by:
I am still struggling with trying to match a user supplied string with strings in a field of a table, where spaces are to be ignored. Arno suggested that I use the Dlookup function, but I...
6
by: Don Sealer | last post by:
I've written this expression for a DLookup function. It works almost alright. What I'm trying to do is type in a description and the ID field (number) populates automatically. It works almost as...
13
by: nzyui | last post by:
Trying to lookup a field from a table called condition this is a separate table not linked to anything: setup as shown Code S M L DG 1 2 3 RI 2 4 5 need...
2
by: Don | last post by:
Can someone help me fix my DLookup problem. I'm far from proficiency with Access. I've been creating databases for several years for work with the help of many of you and trial and error. I have...
2
by: jonvan20 | last post by:
I have been having trouble with a simple Dlookup command that was Reccommended to me by a nice fellow named Vic, On the other hand I have statements like this that wont run they give me a run time...
2
by: Denise | last post by:
Front end is Access 2002, back end is linked Oracle tables. My users need to describe things in feet and inches and want to use the standard ' and " abbrevations. On a testing form I go to a...
7
Breezwell
by: Breezwell | last post by:
This is probably a simple question for someone out there. I understand that the DLookup function takes has the following syntax: DLookup(expression,domain,) From what I have read, domain can...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.