Demo on how to insert records into Multiple tables with one html form and one asp form.

Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 29
November 15, 1999
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement
<br>
<table BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="390" height="63"><br>
<tr><br>
<td height="24"><big><font face="Verdana"><big><strong>Post A Match</strong></big></font></big></td><br>
</tr><br>
</table><BR><br>
<div align="center"><center><p>&nbsp;</p><br>
</center></div><blockquote><br>
<div align="left"><table><br>
<tr><br>
<td ALIGN="right"><strong>User name:</strong></td><br>
<td><input TYPE="TEXT" NAME="YourName" SIZE="25"> </td><br>
</tr><br>
<tr><br>
<td ALIGN="right"><strong>Opponent's name:</strong></td><br>
<td><input TYPE="TEXT" NAME="OpponentName" SIZE="25"> </td><br>
</tr><br>
<tr><br>
<td ALIGN="right"><strong>Games Scores&nbsp; Results:</strong></td><br>
<td>Your Score<strong> <select name="YourScore" size="1"><br>
<option value="12">12</option><br>
<option value="13">13</option><br>
<option value="14">14</option><br>
<option value="15">15</option><br>
</select>&nbsp; </strong>Opp's Score<strong> <select name="OpponentScore" size="1"><br>
<option value="9">9</option><br>
<option value="10">10</option><br>
<option value="11">11</option><br>
</select></strong></td><br>
</tr><br>
</table><br>
<p><input type="Submit" value="Submit Results" name="btnSubmit"> </p><br>
</form><br>
</body><br>
</html></p>
<h3>Page 2--The Process Form</h3>
<p><% @Language="VbScript" %><br>
<% <br>
<br>
<b>'Declare all local variables</b><br>
dim conn<br>
dim strconn<br>
dim Gamers<br>
dim strsql<br>
dim strID<br>
<br>
<b>'Sets the DSN-less connection string to a local variable</b><br>
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("MultiTable.mdb")<br>
<br>
<b>'Opens a connection object</b><br>
set conn = server.createobject("adodb.connection")<br>
conn.open strconn<br>
<br>
<b>'Records when the game was played table</b><br>
set GameRS = Server.Createobject("adodb.recordset")<br>
GameRS.open "tblWhenPlayed", conn, 3, 3<br>
GameRS.addnew <br>
GameRS("WinnersName") = request.form("YourName")<br>
GameRS("LosersName") = request.form("OpponentName")<br>
GameRS("DatePlayed") = Date()<br>
GameRS.update<br>
GameRS.movelast<br>
<br>
<b>'Get the Game ID that is created when the record was created</b><br>
strID = GameRS("GameID")<br>
GameRS.Close<br>
set GameRS = nothing<br>
<br>
<b>'Records Winner's into the Losers table</b><br>
strSQL = "INSERT INTO tblWinners(GameID, ZoneName, NumOfPoints)"<br>
strSQL = strSQL & " SELECT "<br>
strSQL = strSQL & strID & " as text1," <br>
strSQL = strSQL & "'" & request("YourName") & "' as text2,"<br>
strSQL = strSQL & request("YourScore") & " as text3"<br>
conn.execute(strsql)<br>
<br>
<b>'Records Losers Info into the Losers table</b><br>
strSQL = "INSERT INTO tblLosers(GameID, ZoneName, NumOfPoints)"<br>
strSQL = strSQL & " SELECT "<br>
strSQL = strSQL & strID & " as text1," <br>
strSQL = strSQL & "'" & request("OpponentName") & "' as text2,"<br>
strSQL = strSQL & request("OpponentScore") & " as text3"<br>
conn.execute(strsql)<br>
<br>
conn.close<br>
set conn = nothing<br>
<br>
%><br>
</p>
<p><html><br>
<head><br>
<title>Post Score Summary</title><br>
</head><br>
<body><br>
<h1>Your Record has been recorded</h1><br>
<h3>Here is your Unique ID:<% = strID %></h3><br>
<p>This demo has just inserted data into Three different tables</p><br>
</body><br>
</html><br>
</p>

blog comments powered by Disqus
DATABASE CODE ARTICLES

- Deployment of the MobiLink Synchronization M...
- MobiLink Synchronization Wizard in SQL Anywh...
- Finding Matching Records in Data Access Pages
- Using the AccessDataSource Control in VS 2005
- A Closer Look at ADO.NET: The Command Object
- A Closer Look at ADO.NET: The Connection Obj...
- Using ADO to Communicate with the Database, ...
- Code Snippets: Counting Records
- Constraints In Microsoft SQL Server 2000
- Multilingual entries into a DB and to be dis...
- Two combos, one textbox example
- ADO Recordset Paging
- SQL Server Database Creator - .NET Version
- Getting A List of Tables From SQL Server
- Discussion & Listserv Module by Mike Eck...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials