Jump to content
Sign in to follow this  
musicradiolive

Multiple Insert

Recommended Posts

Hi All.I know how to insert data into a database using a form, but how do i go about adding MULTIPLE records?So basiclaly code will be:

Enter This <input type="text" name="this_field1"><br>Enter This <input type="text" name="this_field2"><br>Enter This <input type="text" name="this_field3"><br>

Blah blah blahBUT,Can i have so it does:

Information 1<br>Enter This <input type="text" name="this_field1"><br>Enter This <input type="text" name="this_field2"><br>Enter This <input type="text" name="this_field3"><br><br><br>Information 2<br>Enter This <input type="text" name="this_field1(SECOND RECORD)"><br>Enter This <input type="text" name="this_field2(SECOND RECORD)"><br>Enter This <input type="text" name="this_field3(SECOND RECORD)"><br><br><br>Information 3<br>Enter This <input type="text" name="this_field1(THIRD RECORD)"><br>Enter This <input type="text" name="this_field2(THIRD RECORD)"><br>Enter This <input type="text" name="this_field3(THIRD RECORD)"><br>

The process page which will save the data currently looks like this:

<%Dim adoCon Dim rsAddInformation Dim strSQL Set adoCon = Server.CreateObject("ADODB.Connection")adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("my_database.mdb")Set rsAddInformation = Server.CreateObject("ADODB.Recordset")strSQL = "SELECT tblmine.this_field1, tblmine.this_field2, tblmine.this_field3 FROM tblmine;"rsAddInformation.CursorType = 2rsAddInformation.LockType = 3rsAddInformation.Open strSQL, adoConrsAddInformation.AddNewrsAddInformation.Fields("this_field1") = Request.Form("this_field1")rsAddInformation.Fields("this_field2") = Request.Form("this_field2")rsAddInformation.Fields("this_field3") = Request.Form("this_field3")rsAddInformation.Update[ CODE TO SHOW ADDED INFORMATION WILL GO HERE]%>

Thanks In Advance :)

Share this post


Link to post
Share on other sites

This is my problem-solving method.(It has been tested.)Code for inputing infomation:Information 1<br>Enter This <input type="text" name="this_field1"><br>Enter This <input type="text" name="this_field2"><br>Enter This <input type="text" name="this_field3"><br><br><br>Information 2<br>Enter This <input type="text" name="this_field1"><br>Enter This <input type="text" name="this_field2"><br>Enter This <input type="text" name="this_field3"><br><br><br>Information 3<br>Enter This <input type="text" name="this_field1"><br>Enter This <input type="text" name="this_field2"><br>Enter This <input type="text" name="this_field3"><br>Code for write the records to the MDB file:<%Dim adoCon Dim rsAddInformation Dim strSQL Set adoCon = Server.CreateObject("ADODB.Connection")adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("my_database.mdb")Set rsAddInformation = Server.CreateObject("ADODB.Recordset")strSQL = "SELECT tblmine.this_field1, tblmine.this_field2, tblmine.this_field3 FROM tblmine;"rsAddInformation.CursorType = 2rsAddInformation.LockType = 3rsAddInformation.Open strSQL, adoConDim this_field1(100)Dim this_field2(100)Dim this_field3(100)for i=1 to Request.Form("this_field1").Count()this_field1(i)=Request.Form("this_field1")(i)this_field2(i)=Request.Form("this_field2")(i)this_field3(i)=Request.Form("this_field3")(i)rsAddInformation.AddNewrsAddInformation.Fields("this_field1") = this_field1(i)rsAddInformation.Fields("this_field2") = this_field2(i)rsAddInformation.Fields("this_field3") = this_field3(i)rsAddInformation.UpdatenextrsAddInformation.CloseadoCon.Close%> If it does not work, please tell me. ->>Note:You can edit the "100" of the following if the number of data is very large, that "100" means there are 100 records.Dim this_field1(100)Dim this_field2(100)Dim this_field3(100)

Share this post


Link to post
Share on other sites

Is this correct? I'm not sure whether i got my head around it right or not.

Record 1<br>Title <input type="text" name="title1"><br>Name <input type="text" name="name1"><br>Address <input type="text" name="address1"><br><br><br>Record 2<br>Title <input type="text" name="title2"><br>Name <input type="text" name="name2"><br>Address <input type="text" name="address3"><br><br><br>Record 3<br>Title <input type="text" name="title3"><br>Name <input type="text" name="name3"><br>Address <input type="text" name="address3"><br>

Code for write the records to the MDB file:

<%Dim adoCon Dim rsAddInformation Dim strSQL Set adoCon = Server.CreateObject("ADODB.Connection")adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("data.mdb")Set rsAddInformation = Server.CreateObject("ADODB.Recordset")strSQL = "SELECT mine.title, mine.name, mine.address FROM mine;"rsAddInformation.CursorType = 2rsAddInformation.LockType = 3rsAddInformation.Open strSQL, adoConDim this_field1(100)Dim this_field2(100)Dim this_field3(100)<<<<<<<<<<<<<<<<<<<TRHIS IS THE BIT I DIDN'T QUITE KNOW HOW TO ADJUST THE MOST >>>>>>>>>>>>>>>>>> for i=1 to Request.Form("this_field1").Count()this_field1(i)=Request.Form("this_field1")(i)this_field2(i)=Request.Form("this_field2")(i)this_field3(i)=Request.Form("this_field3")(i)rsAddInformation.AddNewrsAddInformation.Fields("this_field1") = this_field1(i)rsAddInformation.Fields("this_field2") = this_field2(i)rsAddInformation.Fields("this_field3") = this_field3(i)rsAddInformation.UpdatenextrsAddInformation.CloseadoCon.Close%>

Share this post


Link to post
Share on other sites

I think the code should be.... :)Code 1:Record 1<br>Title <input type="text" name="title"><br>Name <input type="text" name="name"><br>Address <input type="text" name="address"><br><br><br>Record 2<br>Title <input type="text" name="title"><br>Name <input type="text" name="name"><br>Address <input type="text" name="address"><br><br><br>Record 3<br>Title <input type="text" name="title"><br>Name <input type="text" name="name"><br>Address <input type="text" name="address"><br>Code 2:<%Dim adoCon Dim rsAddInformation Dim strSQL Set adoCon = Server.CreateObject("ADODB.Connection")adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("data.mdb")Set rsAddInformation = Server.CreateObject("ADODB.Recordset")strSQL = "SELECT * FROM mine;"rsAddInformation.CursorType = 2rsAddInformation.LockType = 3rsAddInformation.Open strSQL, adoConDim title(100)Dim name(100)Dim address(100)for i=1 to Request.Form("title").Count()this_field1(i)=Request.Form("title")(i)this_field2(i)=Request.Form("name")(i)this_field3(i)=Request.Form("address")(i)rsAddInformation.AddNewrsAddInformation.Fields("title") = title(i)rsAddInformation.Fields("name") = name(i)rsAddInformation.Fields("address") = address(i)rsAddInformation.UpdatenextrsAddInformation.CloseadoCon.Close%> If you are inserting only three records, then you can chnage them into:Dim title(3)Dim name(3)Dim address(3)that means there are three arrays.Last, beware of the typing mistakes (including my typing mistakes, I haven't try the code) and if you have any problems, sign a message. Thanks. :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...