Friday, December 14, 2007

How to add an array value to the Recordset?

How to add an array value to the Recordset?

We can create 2 Variant type Arrays: one for storing the field name and another for storing the value. Use the AddNew method to store it to the database.


The ASP codes are written and described as below:

<%

Set conn = Server.CreateObject("Adodb.Connection")

conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

Set rs = Server.CreateObject("Adodb.Recordset")

varF = Array("MemberName", "Location")

varV = Array("Simon", "AU")

rs.open "Member",conn,1,3

rs.AddNew varF, varV 'Add the array value in the database

'We do not need to use the Update method to save it, the ADO will do for you

rs.Close

Set rs = Nothing

%>

No comments: