Current location: Hot Scripts Forums » Programming Languages » ASP » Asp and databases


Asp and databases

Reply
  #1 (permalink)  
Old 06-20-03, 01:49 AM
Ph33r Ph33r is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Question Asp and databases

hey im new to the ASP Scene and just need a little help working on a script so it reads a table and also one field (eg dataID) and if the field equals a number it will show all the data in that row. and also i need the page to work like this..

www.whatever.com/data.asp?DataID=(number here)

thanks for any help u can give me.
Reply With Quote
  #2 (permalink)  
Old 06-20-03, 06:04 AM
Tesco Tesco is offline
ASP Guru
 
Join Date: Jun 2003
Location: UK
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
You need to write a new SQL statement in the page data.asp

I take it you already have a Record set & SQL statement?

If yes, then you need to declare a variable, and assign it the value of querystring DataID, like this:

Dim RequestedID
RequestedID = Request.QueryString("DataID")

You need to do that before your SQL statement. Then change your SQL statement to:

"SELECT * FROM TableName WHERE DataID = " & RequestedID & ""

Haven't tested, but should work.
Reply With Quote
  #3 (permalink)  
Old 06-20-03, 07:45 PM
Gurrutello Gurrutello is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
why dont show your code??
it wil be easyer
saludos
Reply With Quote
  #4 (permalink)  
Old 06-23-03, 07:22 PM
edshere@macventure.com edshere@macventure.com is offline
New Member
 
Join Date: Jun 2003
Location: Kansas
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb here you go.

'Grab desired variable from url
idval = request.querystring("id")

'Specify driver and path.
strconn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("DB_NAME.mdb")

'Create ado object
set conn = server.createobject("adodb.connection")

'Instruct what to open
conn.open strconn

'SQL query
sql = "Select * from TABLE_NAME where FIELD_NAME = "&idval&""


'Open connection and execute query as recordset
set rs = conn.execute(sql)

'Write Data to the page
response.write rs("FIELD_NAME_1")
response.write rs("FIELD_NAME_2")
'Don't forget to close the connection

'Close connection
conn.close
set conn = nothing
Reply With Quote
  #5 (permalink)  
Old 06-23-03, 07:27 PM
edshere@macventure.com edshere@macventure.com is offline
New Member
 
Join Date: Jun 2003
Location: Kansas
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
'ooops forgot something.
'Let me try this again.

'Grab desired variable from url
idval = request.querystring("id")

'Specify driver and path.
strconn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("DB_NAME.mdb")

'Create ado object
set conn = server.createobject("adodb.connection")

'Instruct what to open
conn.open strconn

'SQL query
sql = "Select * from TABLE_NAME where FIELD_NAME = "&idval&""


'Open connection and execute query as recordset
set rs = conn.execute(sql)

'Check to see if a record exists.

if rs.eof then '****************************

response.write "Could not find that record. Please try again."
'or
'response.redirect "where_ever.asp"

else '****************************

'Write Data to the page
response.write rs("FIELD_NAME_1")
response.write rs("FIELD_NAME_2")

End if '****************************


'Close connection
conn.close
set conn = nothing
Reply With Quote
  #6 (permalink)  
Old 06-24-03, 01:34 AM
Ph33r Ph33r is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up

Thankz this is really helpfull, problem is the website im building is going to take months for me to complete, all because there is only one person building, coding, debuging and designing the whole site and that one person is me. so thanks for helping me with my problem, im going to try that now

Ph33r
Reply With Quote
  #7 (permalink)  
Old 06-26-03, 04:36 PM
Gurrutello Gurrutello is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
the code seems ok
what its the error you get??
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 04:00 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.