Jump to content

asp and access database related


denny911

Recommended Posts

Helloi've made a simple MS access database to store the news articles for my future info portal.the database is named test.mdb . It contains a table named news_tblIt looks something like this:id | news_header | news_content-------------------------------------------------------------------------------------------123 SOME TITLE corresponding content456 OTHER TITLE other contentetc._____________________________________________________now, i have this ASP code:<%set conn=Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open(Server.Mappath("test.mdb"))set rs = Server.CreateObject("ADODB.recordset")rs.Open "Select * from news_tbl", conn'The first number indicates how many records to copy'The second number indicates what recordnumber to start onp=rs.GetRows(2,0)%><% response.write(p(1,0))%><br> --------> i insert this code where i want my title to appear<%response.write(p(2,0))%> --------> i insert this where i want the content to appear<%rs.closeconn.close%>this code displays the value (content) of corresponding fields above (in this case, it will displaySOME TITLEcorresponding contentand that is only for the table row which id is 123.BUT.. i intend to have a lots of links which will be something like this: http://www.my-site.info/news/news-details.asp?id=xxx (xxx=any 3 numbers).. when a user clicks on such a link, i want the code to display the records from a row with the id=xxxwhat i have to do in order to have the page news-details.asp displaying records from only the table row with the id contained in the link?if anyone helps me in any way, i will be very grateful.

Link to comment
Share on other sites

Ok, so fisrt you need to recuparate the id value from your url string like this :

Dim idid = Request.QueryString("id")

Then you just insert this value into your query like this :

<%'here you open the connectionSet rs = Server.CreateObject("ADODB.recordset")sql = " SELECT * FROM newst_tlb WHERE ID = '" & id & "' "rs.Open sql, con'here you display the fields and close connection and recordset%>

Last thing, instead of using a SELECT *, you should better specify wich fields your looking for : SELECT news_header, news_content for example. That is a good way to gain some loading time.

Link to comment
Share on other sites

  • 2 weeks later...
Ok, so fisrt you need to recuparate the id value from your url string like this :
Dim idid = Request.QueryString("id")

Then you just insert this value into your query like this :

<%'here you open the connectionSet rs = Server.CreateObject("ADODB.recordset")sql = " SELECT * FROM newst_tlb WHERE ID = '" & id & "' "rs.Open sql, con'here you display the fields and close connection and recordset%>

Last thing, instead of using a SELECT *, you should better specify wich fields your looking for : SELECT news_header, news_content for example. That is a good way to gain some loading time.

Sorry, this is NOT working.. I've made a new post, so if you are interested, you can look what the problem is..
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...