Forums
This topic is locked
How to insert multiple records at once??
Posted 03 Dec 2001 14:27:57
1
has voted
03 Dec 2001 14:27:57 Simon Eckler posted:
I have a form in Ultradev with 10 textfields with NAME,LASTNAME,ADRESS....and a Submit-Button.When i click on the Submit-Button i want to insert all records at once into my Access Database into different tabels.
Ultradev only supports to insert 1 record at once.
How can i do this?
Please help me <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>
Replies
Replied 03 Dec 2001 16:04:31
03 Dec 2001 16:04:31 Viktor Farcic replied:
Use Command/Stored Procedure. It's similar to Insert/Update/Delete Query in Access.
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
I have a form in Ultradev with 10 textfields with NAME,LASTNAME,ADRESS....and a Submit-Button.
When i click on the Submit-Button i want to insert all records at once into my Access Database into different tabels.
Ultradev only supports to insert 1 record at once.
How can i do this?
Please help me <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
I have a form in Ultradev with 10 textfields with NAME,LASTNAME,ADRESS....and a Submit-Button.
When i click on the Submit-Button i want to insert all records at once into my Access Database into different tabels.
Ultradev only supports to insert 1 record at once.
How can i do this?
Please help me <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 03 Dec 2001 16:38:05
03 Dec 2001 16:38:05 Simon Eckler replied:
hmm,i'm not sure how to write this.
Can you give me an example (code) for this? <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Thanks for your help!
Can you give me an example (code) for this? <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Thanks for your help!
Replied 03 Dec 2001 19:34:33
03 Dec 2001 19:34:33 Owen Eastwick replied:
Here's some code from a user registration page that should give you the general idea:
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/YourConnectionPage.asp" -->
<% If Request("Submit" <> "" Then 'Check to see that the user has submitted the form %>
<%
'----------------------------------
' Make sure the username is unique
'----------------------------------
Dim comSpUserCheckUnique__UserName
comSpUserCheckUnique__UserName = ""
if(Request("txtUserName" <> "" then comSpUserCheckUnique__UserName = Request("txtUserName"
%>
<%
set comSpUserCheckUnique = Server.CreateObject("ADODB.Command"
comSpUserCheckUnique.ActiveConnection = MM_YourConnectionPage_STRING
comSpUserCheckUnique.CommandText = "dbo.spUserCheckUnique"
comSpUserCheckUnique.Parameters.Append comSpUserCheckUnique.CreateParameter("@RETURN_VALUE", 3, 4)
comSpUserCheckUnique.Parameters.Append comSpUserCheckUnique.CreateParameter("@UserName", 200, 1,20,comSpUserCheckUnique__UserName)
comSpUserCheckUnique.CommandType = 4
comSpUserCheckUnique.CommandTimeout = 0
comSpUserCheckUnique.Prepared = true
set rsUserName = comSpUserCheckUnique.Execute
rsUserName_numRows = 0
%>
<%
If rsUserName.EOF And rsUserName.BOF Then ' If username is unique
%>
<%
'--------------------------------------
' Collect all the elements from the form
'--------------------------------------
if(Request("txtUserName" <> "" then ComUserInsert__varUsername = Request("txtUserName"
if(Request("txtPassword" <> "" then ComUserInsert__varPassword = Request("txtPassword"
%>
<%
if(Request("txtUserName" <> "" then comUserDetailInsert__varUserName = Request("txtUserName"
if(Request("selSalutation" <> "" then comUserDetailInsert__varUserSalutation = Request("selSalutation"
if(Request("txtFirstName" <> "" then comUserDetailInsert__varFirstName = Request("txtFirstName"
if(Request("txtLastName" <> "" then comUserDetailInsert__varLastName = Request("txtLastName"
if(Request("txtAddress" <> "" then comUserDetailInsert__varUserAddress = Request("txtAddress"
if(Request("txtTown" <> "" then comUserDetailInsert__varUserTown = Request("txtTown"
if(Request("txtCounty" <> "" then comUserDetailInsert__varUserCounty = Request("txtCounty"
if(Request("txtPostCode" <> "" then comUserDetailInsert__varUserPostCode = Request("txtPostCode"
if(Request("txtTel" <> "" then comUserDetailInsert__varUserTel = Request("txtTel"
if(Request("txtMobile" <> "" then comUserDetailInsert__varUserMobile = Request("txtMobile"
if(Request("txtEmail" <> "" then comUserDetailInsert__varUserEmail = Request("txtEmail"
if(Request("hidDOBDate" <> "" then comUserDetailInsert__varUserDateOfBirth = Request("hidDOBDate"
if(Request("txtEmployer" <> "" then comUserDetailInsert__varUserEmployer = Request("txtEmployer"
if(Request("hidLicenceDate" <> "" then comUserDetailInsert__varUserLicenceDate = Request("hidLicenceDate"
if(Request("radLicenceType" <> "" then comUserDetailInsert__varUserLicenceType = Request("radLicenceType"
if(Request("hidCertificates" <> "" then comUserDetailInsert__varUserCertificates = Request("hidCertificates"
%>
<%
'-------------------------------------------------------
'Insert the username and password into the Users table
'-------------------------------------------------------
set ComUserInsert = Server.CreateObject("ADODB.Command"
ComUserInsert.ActiveConnection = MM_YourConnectionPage_STRING
ComUserInsert.CommandText = "INSERT INTO tblUsers (UserName,UserPassword,UserLevel,UserType) VALUES ('" + Replace(ComUserInsert__varUsername, "'", "''" + "','" + Replace(ComUserInsert__varPassword, "'", "''" + "',3,3) "
ComUserInsert.CommandType = 1
ComUserInsert.CommandTimeout = 0
ComUserInsert.Prepared = true
ComUserInsert.Execute()
set ComUserInsert = Nothing
%>
<%
'----------------------------------------------------------------------------
'Insert the username and all the detail information into the UserDetail table
'----------------------------------------------------------------------------
set comUserDetailInsert = Server.CreateObject("ADODB.Command"
comUserDetailInsert.ActiveConnection = MM_YourConnectionPage_STRING
comUserDetailInsert.CommandText = "INSERT INTO tblUserDetails (UserName,UserSalutation,UserFirstName,UserLastName,UserAddress,UserTown,UserCounty,UserPostCode,UserTel,UserMobile,UserEmail,UserDateOfBirth,UserEmployer,UserLicenceDate,UserLicenceType,UserCertificates) VALUES ('" + Replace(comUserDetailInsert__varUserName, "'", "''" + "','" + Replace(comUserDetailInsert__varUserSalutation, "'", "''" + "','" + Replace(comUserDetailInsert__varFirstName, "'", "''" + "','" + Replace(comUserDetailInsert__varLastName, "'", "''" + "','" + Replace(comUserDetailInsert__varUserAddress, "'", "''" + "','" + Replace(comUserDetailInsert__varUserTown, "'", "''" + "','" + Replace(comUserDetailInsert__varUserCounty, "'", "''" + "','" + Replace(comUserDetailInsert__varUserPostCode, "'", "''" + "','" + Replace(comUserDetailInsert__varUserTel, "'", "''" + "','" + Replace(comUserDetailInsert__varUserMobile, "'", "''" + "','" + Replace(comUserDetailInsert__varUserEmail, "'", "''" + "','" + Replace(comUserDetailInsert__varUserDateOfBirth, "'", "''" + "','" + Replace(comUserDetailInsert__varUserEmployer, "'", "''" + "','" + Replace(comUserDetailInsert__varUserLicenceDate, "'", "''" + "','" + Replace(comUserDetailInsert__varUserLicenceType, "'", "''" + "','" + Replace(comUserDetailInsert__varUserCertificates, "'", "''" + "') "
comUserDetailInsert.CommandType = 1
comUserDetailInsert.CommandTimeout = 0
comUserDetailInsert.Prepared = true
comUserDetailInsert.Execute()
set ComUserDetailInsert = Nothing
%>
<%
'-------------------------------------------------
'If username already exists redirect to fail page
'-------------------------------------------------
Else
Response.Redirect("usertaken.asp"
End If ' Recordset Empty
%>
<%
'-------------------------------------------------------
'If registraion succesful redirect to confirmation page
'-------------------------------------------------------
Response.Redirect("registerthanks.asp"
%>
<%
%>
<% End If ' Form Submitted %>
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/YourConnectionPage.asp" -->
<% If Request("Submit" <> "" Then 'Check to see that the user has submitted the form %>
<%
'----------------------------------
' Make sure the username is unique
'----------------------------------
Dim comSpUserCheckUnique__UserName
comSpUserCheckUnique__UserName = ""
if(Request("txtUserName" <> "" then comSpUserCheckUnique__UserName = Request("txtUserName"
%>
<%
set comSpUserCheckUnique = Server.CreateObject("ADODB.Command"
comSpUserCheckUnique.ActiveConnection = MM_YourConnectionPage_STRING
comSpUserCheckUnique.CommandText = "dbo.spUserCheckUnique"
comSpUserCheckUnique.Parameters.Append comSpUserCheckUnique.CreateParameter("@RETURN_VALUE", 3, 4)
comSpUserCheckUnique.Parameters.Append comSpUserCheckUnique.CreateParameter("@UserName", 200, 1,20,comSpUserCheckUnique__UserName)
comSpUserCheckUnique.CommandType = 4
comSpUserCheckUnique.CommandTimeout = 0
comSpUserCheckUnique.Prepared = true
set rsUserName = comSpUserCheckUnique.Execute
rsUserName_numRows = 0
%>
<%
If rsUserName.EOF And rsUserName.BOF Then ' If username is unique
%>
<%
'--------------------------------------
' Collect all the elements from the form
'--------------------------------------
if(Request("txtUserName" <> "" then ComUserInsert__varUsername = Request("txtUserName"
if(Request("txtPassword" <> "" then ComUserInsert__varPassword = Request("txtPassword"
%>
<%
if(Request("txtUserName" <> "" then comUserDetailInsert__varUserName = Request("txtUserName"
if(Request("selSalutation" <> "" then comUserDetailInsert__varUserSalutation = Request("selSalutation"
if(Request("txtFirstName" <> "" then comUserDetailInsert__varFirstName = Request("txtFirstName"
if(Request("txtLastName" <> "" then comUserDetailInsert__varLastName = Request("txtLastName"
if(Request("txtAddress" <> "" then comUserDetailInsert__varUserAddress = Request("txtAddress"
if(Request("txtTown" <> "" then comUserDetailInsert__varUserTown = Request("txtTown"
if(Request("txtCounty" <> "" then comUserDetailInsert__varUserCounty = Request("txtCounty"
if(Request("txtPostCode" <> "" then comUserDetailInsert__varUserPostCode = Request("txtPostCode"
if(Request("txtTel" <> "" then comUserDetailInsert__varUserTel = Request("txtTel"
if(Request("txtMobile" <> "" then comUserDetailInsert__varUserMobile = Request("txtMobile"
if(Request("txtEmail" <> "" then comUserDetailInsert__varUserEmail = Request("txtEmail"
if(Request("hidDOBDate" <> "" then comUserDetailInsert__varUserDateOfBirth = Request("hidDOBDate"
if(Request("txtEmployer" <> "" then comUserDetailInsert__varUserEmployer = Request("txtEmployer"
if(Request("hidLicenceDate" <> "" then comUserDetailInsert__varUserLicenceDate = Request("hidLicenceDate"
if(Request("radLicenceType" <> "" then comUserDetailInsert__varUserLicenceType = Request("radLicenceType"
if(Request("hidCertificates" <> "" then comUserDetailInsert__varUserCertificates = Request("hidCertificates"
%>
<%
'-------------------------------------------------------
'Insert the username and password into the Users table
'-------------------------------------------------------
set ComUserInsert = Server.CreateObject("ADODB.Command"
ComUserInsert.ActiveConnection = MM_YourConnectionPage_STRING
ComUserInsert.CommandText = "INSERT INTO tblUsers (UserName,UserPassword,UserLevel,UserType) VALUES ('" + Replace(ComUserInsert__varUsername, "'", "''" + "','" + Replace(ComUserInsert__varPassword, "'", "''" + "',3,3) "
ComUserInsert.CommandType = 1
ComUserInsert.CommandTimeout = 0
ComUserInsert.Prepared = true
ComUserInsert.Execute()
set ComUserInsert = Nothing
%>
<%
'----------------------------------------------------------------------------
'Insert the username and all the detail information into the UserDetail table
'----------------------------------------------------------------------------
set comUserDetailInsert = Server.CreateObject("ADODB.Command"
comUserDetailInsert.ActiveConnection = MM_YourConnectionPage_STRING
comUserDetailInsert.CommandText = "INSERT INTO tblUserDetails (UserName,UserSalutation,UserFirstName,UserLastName,UserAddress,UserTown,UserCounty,UserPostCode,UserTel,UserMobile,UserEmail,UserDateOfBirth,UserEmployer,UserLicenceDate,UserLicenceType,UserCertificates) VALUES ('" + Replace(comUserDetailInsert__varUserName, "'", "''" + "','" + Replace(comUserDetailInsert__varUserSalutation, "'", "''" + "','" + Replace(comUserDetailInsert__varFirstName, "'", "''" + "','" + Replace(comUserDetailInsert__varLastName, "'", "''" + "','" + Replace(comUserDetailInsert__varUserAddress, "'", "''" + "','" + Replace(comUserDetailInsert__varUserTown, "'", "''" + "','" + Replace(comUserDetailInsert__varUserCounty, "'", "''" + "','" + Replace(comUserDetailInsert__varUserPostCode, "'", "''" + "','" + Replace(comUserDetailInsert__varUserTel, "'", "''" + "','" + Replace(comUserDetailInsert__varUserMobile, "'", "''" + "','" + Replace(comUserDetailInsert__varUserEmail, "'", "''" + "','" + Replace(comUserDetailInsert__varUserDateOfBirth, "'", "''" + "','" + Replace(comUserDetailInsert__varUserEmployer, "'", "''" + "','" + Replace(comUserDetailInsert__varUserLicenceDate, "'", "''" + "','" + Replace(comUserDetailInsert__varUserLicenceType, "'", "''" + "','" + Replace(comUserDetailInsert__varUserCertificates, "'", "''" + "') "
comUserDetailInsert.CommandType = 1
comUserDetailInsert.CommandTimeout = 0
comUserDetailInsert.Prepared = true
comUserDetailInsert.Execute()
set ComUserDetailInsert = Nothing
%>
<%
'-------------------------------------------------
'If username already exists redirect to fail page
'-------------------------------------------------
Else
Response.Redirect("usertaken.asp"
End If ' Recordset Empty
%>
<%
'-------------------------------------------------------
'If registraion succesful redirect to confirmation page
'-------------------------------------------------------
Response.Redirect("registerthanks.asp"
%>
<%
%>
<% End If ' Form Submitted %>
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
Replied 05 Dec 2001 11:18:02
05 Dec 2001 11:18:02 Simon Eckler replied:
Thanks a lot for your help OWEN!
That is a very good example around my problem to solve
That is a very good example around my problem to solve
Replied 05 Dec 2001 16:38:04
05 Dec 2001 16:38:04 Kent Steelman replied:
Help me more on your problem. Are you collecting information on your form where some of the data will go to one table, other data will go to another table, and so on and so forth... if so... there may be a simpler solution. Set up a querry in access that will allow you (in Access) to update to all of the tables in the database at once. Once you have done this, you can set your form to access the query, the query is now a virtual table, submitting to the query turns on the query in the database writing all relavent data to the tables related to the query. However you must have appropriate primary and secondary keys in the tables so that the tables will relate to each other. Otherwise the query will not work.
Kent
Wm. Kent Steelman
Kent
Wm. Kent Steelman
Replied 09 Dec 2001 03:57:02
09 Dec 2001 03:57:02 Andrew Ross replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Here's some code from a user registration page that should give you the general idea:
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Thanks for the info Owen. I have designed a database, as well as search and results pages, based on your "Advanced Search Tutorial". My database is for Suppliers and Services and I have subsituted your Genres, Formats and Albums tables for Provinces, Categories and Contacts. I also have an intermediate table called ContactCategories that serves the same purpose as your AlbumFormats table. After much work I finally have the search and results pages working fine, but now I'm stuck on the insert and update pages. Like many others I have been frustrated to find out that UltraDev only allows you to create pages that insert into one table.
How would you design an insert and update page for your Album database that lets you select different combinations of formats for different albums? That's the dilemma I am now facing as many of my Suppliers and Services fall into more than one category.
Any help you can offer will be greatly appreciated. Please bear in mind that I am also a new user with little experience in SQL or VisualBasic.
Andrew Ross
Here's some code from a user registration page that should give you the general idea:
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Thanks for the info Owen. I have designed a database, as well as search and results pages, based on your "Advanced Search Tutorial". My database is for Suppliers and Services and I have subsituted your Genres, Formats and Albums tables for Provinces, Categories and Contacts. I also have an intermediate table called ContactCategories that serves the same purpose as your AlbumFormats table. After much work I finally have the search and results pages working fine, but now I'm stuck on the insert and update pages. Like many others I have been frustrated to find out that UltraDev only allows you to create pages that insert into one table.
How would you design an insert and update page for your Album database that lets you select different combinations of formats for different albums? That's the dilemma I am now facing as many of my Suppliers and Services fall into more than one category.
Any help you can offer will be greatly appreciated. Please bear in mind that I am also a new user with little experience in SQL or VisualBasic.
Andrew Ross
Replied 09 Dec 2001 14:34:37
09 Dec 2001 14:34:37 Owen Eastwick replied:
A good question, and quite a common one on the forums.
I'm really busy at the moment, I have a rapidly aproaching deadline for an important project I'm working on. However when I get time I want to extend my tutorial site to include topics such as Multiple Table Insertions.
Until then, try the search, here and at: www.howtoultradev.com, look for "insert multiple tables" and "update multiple tables" I'm sure there are a few posts that I've come accross which may be of use.
You could also take a look at: www.chronoworks.com/ud40/tutorial8/index.asp, Not overly beginner friendly I'm afraid.
Good Luck
Owen.
I'm really busy at the moment, I have a rapidly aproaching deadline for an important project I'm working on. However when I get time I want to extend my tutorial site to include topics such as Multiple Table Insertions.
Until then, try the search, here and at: www.howtoultradev.com, look for "insert multiple tables" and "update multiple tables" I'm sure there are a few posts that I've come accross which may be of use.
You could also take a look at: www.chronoworks.com/ud40/tutorial8/index.asp, Not overly beginner friendly I'm afraid.
Good Luck
Owen.
Replied 12 Dec 2001 21:03:59
12 Dec 2001 21:03:59 Kent Steelman replied:
One other location for more information. This is a Tutorial on UDZONE got to the following url .... well written and tell you how and the advantages of using querries in a database....
stardeveloper.com:8080/articles/010701-1.shtml
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
I have a form in Ultradev with 10 textfields with NAME,LASTNAME,ADRESS....and a Submit-Button.
When i click on the Submit-Button i want to insert all records at once into my Access Database into different tabels.
stardeveloper.com:8080/articles/010701-1.shtml
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
I have a form in Ultradev with 10 textfields with NAME,LASTNAME,ADRESS....and a Submit-Button.
When i click on the Submit-Button i want to insert all records at once into my Access Database into different tabels.