Current location: Hot Scripts Forums » Programming Languages » ASP » QueryString and retrieve data from database


QueryString and retrieve data from database

Reply
  #1 (permalink)  
Old 08-11-03, 09:53 AM
pjm pjm is offline
New Member
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Retrieve data from database

Hello.

I'm relatively new to ASP (VBscript) and I need the following help:

My goal is to retrieve the data from a cell column (access database) that is on the same row as other data cell which I know. How to do this?

Thanks for any help!

Last edited by pjm; 08-11-03 at 10:17 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-11-03, 11:53 AM
angst angst is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
sql = "select * from TableName where SomeData=SomeOtherData"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-11-03, 01:06 PM
Shane Shane is offline
Coding Addict
 
Join Date: Jun 2003
Location: Maryland, US
Posts: 268
Thanks: 0
Thanked 0 Times in 0 Posts
This should work...

Replace "column_name" with the column name you want to get information from. Replace "table_name" with your table name. Replace "another_column" with the name of the column that has the known value.

This code works well if you only want to get one record/result. If you want bring back multiple records, you will have to create a loop.
Code:
Dim sql, value
' Define a connection object
Set conn = Server.CreateObject("ADODB.Connection")
' open the connection
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database.mdb") & ";" 

sql = "select column_name from table_name where another_column='something'"



Set RS = conn.Execute(sql)

If NOT RS.EOF Then
value = RS("column_name")
Else
value = "Record not found"
End If

RS.Close
Set RS = Nothing
conn.Close
Set conn = nothing

Response.Write(value)
__________________
Shane Bauer
Microsoft Certified Professional (MCP) - ASP.NET
ASP/ASP.net, C#, VB/VB.NET, PHP, Perl, SQL
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 08-11-03, 03:21 PM
pjm pjm is offline
New Member
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Shane and angst for your answers.

Shane, thanks for writing the code in a very understanding way. It was exactly what I needed and it works perfectly. Thanks again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 07:32 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.