Click to See Complete Forum and Search --> : Database help for newbie?


ianripping
02-23-2004, 06:53 AM
I have this code: -

<%
Dim Conn
Dim Rs
Dim sql
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("FeedBack.mdb")
sql= "SELECT name, comments FROM tblFeeds;"
Rs.Open sql, Conn
Do While not Rs.EOF
Response.Write ("============================================="&"<br>")
Response.Write ("Name: " & "<font color='red'>" & Rs("name") & "</font>")
Response.Write ("<br>")
Response.Write ("Comment: " & "<font color='red'>" & Rs("comments") & "</font>")
Response.Write ("<br>")
Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
Set Conn = Nothing
%>

It looks at all of the database records. Could I make a page which looks at the first record, then at the bottom of the page there is a next button. This would cut this record from the origional database to a new one, then view then next record in the origional database?

buntine
02-23-2004, 07:35 AM
Hey.

This is achieved quite simply.. The code you have currently could easily achieve the desired result with just a tad of editing.

We could set it up so; The user enter the address into the browser, say, http://www.yoursite.com/showrec.asp, for arguments sake.
The first record is grabbed from the database and displayed for the user to see. When they click the 'next ->' link, the same page is reloaded, but the next record is displayed.

To do this we use a queryString variable like so:

http://www.yoursite.com/showrec.asp?recID=1


Then, in your code we pick out the correct record using the value we have aquired from the queryString. Take a look at the following code snippet for an idea of how this is achieved.

dim recID = request.queryString("recID")

if isEmpty(recID) or recID < 0 then
recID = 1
end if

sql = "SELECT * FROM tblFeeds WHERE id=" & recID


At the bottom of the page, we construct our hyperlink in the following way.


<a href="<%= Split(request.serverVariables("SCRIPT_NAME"),"?")(0) & "?recID=" & CInt(recID + 1) %>">Next Page</a>


Hope this help you out.

Regards,
Andrew Buntine.

ianripping
02-23-2004, 08:39 AM
Yeah thi sis great, all I now ask is a way for every record viewed to be cut into a new database and deleted from the old one?

buntine
02-23-2004, 08:59 AM
Has this 'new database' already been created? If so, you could use a simple insert statement to put the desired record into the database.

If this is the case, post and i will help you. If you need help, that is.

ianripping
02-23-2004, 10:31 AM
Well couldnt it be done through a command in asp?

Like: -

Copy this record i am looking at into here.mdb
Now delete this record from this.mdb
Now goto next record.


Possible?

buntine
02-23-2004, 12:33 PM
Yes, all your have to do is add a new SQL query in your ASP code...


connTwo = server.createObject("ADODB.connection")

'''Your connTwo connection string.

sql_query = "DELETE * FROM TableName WHERE recID = " & recID
connTwo.execute(sql_query)

connTwo.close
set connTwo = nothing


Does this help?

ianripping
02-23-2004, 01:43 PM
excellent. Thnks