Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello I think I have managed to

Status
Not open for further replies.

LaPluma

Programmer
Feb 3, 2002
139
DE
Hello

I think I have managed to learn how to display the records my MSAccess 2000 database contains.

And I think I have managed to understand how SQL inserts records into a database (partly through the kind assistance of one or two folks here).

What I would now like to do, is to be able to show the visitor a Web page which holds all the records, including those newly inserted records.

In other words, the visitor will see a Web page with database records. There will be 2 insert boxes (first namne and last name) and a submit button for him to add his own records. Then, having clicked submit, I hope to be able to show him all the records in the DB, plus the records he has just added.

The code I have so far for 'display records' is:

(test.asp)

<%@language=vbscript%>

<%
Option Explicit

Dim ConnectionString
Dim connObj
Dim sql
Dim oRS

ConnectionString=&quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & Server.MapPath(&quot;\stevehigham\db\testDB.mdb&quot;) & &quot;;&quot; & _
&quot;Persist Security Info=False&quot;

Set ConnObj = Server.CreateObject(&quot;ADODB.Connection&quot;)
connObj.Open ConnectionString

sql = &quot;select * from Table1&quot;
sql = &quot;SELECT girlSurname, girlFirst FROM Table1 ORDER BY girlSurname&quot;

Set oRS = connObj.Execute(sql)
Do While Not oRS.EOF
Response.Write(oRS(&quot;girlFirst&quot;) & &quot; - &quot; & oRS(&quot;girlSurname&quot;) & &quot;<br>&quot;)
oRS.MoveNext
Loop

oRS.Close
connObj.Close

Set oRS = Nothing
Set connObj = Nothing
%>

and the code I have for INSERT INTO is:

<%
Option Explicit

Dim ConnectionString, connObj, sql, frmFirst, frmSur

frmFirst = Request.Form(&quot;first&quot;)
frmSur = Request.Form(&quot;sur&quot;)

ConnectionString=&quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & Server.MapPath(&quot;\stevehigham\db\testDB.mdb&quot;) & &quot;;&quot; & _
&quot;Persist Security Info=False&quot;

Set ConnObj = Server.CreateObject(&quot;ADODB.Connection&quot;)
connObj.Open ConnectionString

sql = &quot;select * from Table1&quot;
sql = &quot;INSERT INTO Table1 (girlFirst, girlSurname) VALUES ('&quot; & frmFirst & &quot;','&quot; & frmSur & &quot;')&quot;

connObj.Execute(sql)

connObj.Close

Set connObj = Nothing
%>
And finally the form I have is:

<HTML>
<HEAD>
<TITLE>
</TITLE>

<BODY>

<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;page2.asp&quot;>
<input type=&quot;text&quot; name=&quot;first&quot;>
<input type=&quot;text&quot; name=&quot;sur&quot;>
<input type=&quot;text&quot; value=&quot;Clear&quot;>
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Add&quot;>
</form>

</BODY>
</HTML>

Moreover, is it possible to achieve what I am aiming for, without creating more asp files (I already have 3).

Many thanks for any suggestions on how to do this.

LaPluma


 
[tt]
Try adding :

response.redirect &quot;test.asp&quot; after inserting to your database, this will allow the recordset to display the newly added information.

banana.gif
rockband.gif
Banana.gif

 
Many thanks Tony.

That was quick, short, and sweet!

I inserted it here:

sql = &quot;INSERT INTO Table1 (girlFirst, girlSurname) VALUES ('&quot; & frmFirst & &quot;','&quot; & frmSur & &quot;')&quot;

connObj.Execute(sql)
response.redirect &quot;test.asp&quot;

connObj.Close

and it worked a treat. very many thanks.

Best wsihes

LaPluma

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top