| Welcome to Webforumz.com. |
|
Jan 27th, 2008, 21:49
|
#1 (permalink)
|
|
New Member
Join Date: Dec 2007
Location: Los Angeles
Posts: 4
|
Get value from SQL string ?
Hi all,
I am trying to get the value from a SQL string and store it in a variable but i'm guessing DLookup is not used in VBScript/ASP as it is with Access/VBA which is my background so the synax below is of course not working !
- HTML: Select all
strvalue = dlookup("PicInsert") FROM tblCon WHERE "Name" = Request.Form("contributor")
How would I go about doing this ?
Thanks in advance,
Mitch...
Last edited by Monie; Jan 28th, 2008 at 00:34.
Reason: adding the [html] tag for asp code...
|
|
|
Jan 28th, 2008, 01:06
|
#2 (permalink)
|
|
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,567
|
Re: Get value from SQL string ?
You are right about "DLookup is not used in VBScript/ASP"!
But there is a VBScript Function that you could use, It imitates the functionality of the MS Access function of the same name which is like the one that you are using ^
- Code: Select all
strvalue = dlookup("PicInsert") FROM tblCon WHERE "Name" = Request.Form("contributor")
I am not sure that you use the correct syntax for your code above ^ but from what I understand when I see your code is that you are trying to retrieve the PicInsert field from the tblCon table where the Name is from your contributor input field. This is the same as the following SQL statement in more organize and fast way:
- HTML: Select all
<%
Dim strvalue, name
name = Request.Form("contributor")
strvalue = ("SELECT PicInsrt FROM tblConn WHERE Name= '"& name &"'")
%>
Note: when retrieving a string value, you must put ' around them. " is for numbers. Assign any value that you would like to search into a variable for fast script execution (Like what I have done with your Request.Form)
__________________
Last edited by Monie; Jan 28th, 2008 at 01:08.
|
|
|
Jan 29th, 2008, 13:40
|
#3 (permalink)
|
|
Up'n'Coming Member
Join Date: Sep 2007
Location: Wales, UK
Age: 35
Posts: 75
|
Re: Get value from SQL string ?
The only Comment I will make to Monie's code is not to use reserved names like "name" but rather use something like "vName", I always use v's in front of variables to clearly denote them.
Have a look at this page for a list of reserved names - http://www.webthang.co.uk/tuts/tuts_...rds/rwords.asp
Hope this helps. 
__________________
Languages: ASP, RUBY(a little), XML, XHTML, CSS, JavaScript, JQuery - www.bizmo.co.uk
|
|
|
Jan 29th, 2008, 23:53
|
#4 (permalink)
|
|
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,567
|
Re: Get value from SQL string ?
Thanks for the tips robbied!
So the code should look like this:
- HTML: Select all
<%
Dim strvalue, vName
vName = Request.Form("contributor")
strvalue = "SELECT PicInsrt FROM tblConn WHERE Name= '"& vName &"'"
%>
and you should consider changing your database field name as well, "Name"!
__________________
Last edited by Monie; Jan 30th, 2008 at 07:36.
|
|
|
Jan 30th, 2008, 07:13
|
#5 (permalink)
|
|
Up'n'Coming Member
Join Date: Sep 2007
Location: Wales, UK
Age: 35
Posts: 75
|
Re: Get value from SQL string ?
Kind of, I would also rename the database field "Name" to UserName or something as it is also a reserved name.
__________________
Languages: ASP, RUBY(a little), XML, XHTML, CSS, JavaScript, JQuery - www.bizmo.co.uk
|
|
|
Jan 30th, 2008, 07:39
|
#6 (permalink)
|
|
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,567
|
Re: Get value from SQL string ?
Yeah... that sort that out! 
Instead of using VBScript function, you should consider just stick with simple SQL statement to do just what you wanted for faster script execution.
__________________
|
|
|
| Thread Tools |
|
|
| Rate This Thread |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|