Forums

ASP

This topic is locked

Inserting records using own VB code

Posted 30 Jul 2001 10:47:07
1
has voted
30 Jul 2001 10:47:07 Bec C posted:
When I use this code to insert a record into a DB I get a type Mismatch error if any of the fields are set to be a number type.

How do I specify the type of data to pass across as the UD insert function does?

I would rather keep to using this code as it is easier for others to read and update.


<%
' *** Insert Record: construct a sql insert statement and execute it

set objDBConn = Server.CreateObject("ADODB.Connection"
strConn = MM_connIdiumCustomerDB_STRING
objDBConn.Open strConn
strCommandText = "SELECT * FROM customers"
'objDBConn.Execute strCommandText, , adCmdText

Dim fieldNames()
Dim fieldValues()

ReDim Preserve fieldNames(3)
ReDim Preserve fieldValues(3)

fieldNames(0) = "firstname"
fieldNames(1) ="lastname"
fieldNames(2) ="company_name"
fieldNames(3) ="job_title"


fieldValues(0) = request.form("firstname"
fieldValues(1) = request.form("lastname"
fieldValues(2) = request.form("company_name"
fieldValues(3) = request.form("job_title"


'The Addnew functions create a new record
rsCustomerDB.AddNew fieldNames(0), fieldValues(0)

'Now a new record has been created using firstname as the starter we must update the record
for i = 1 to 3
rsCustomerDB.Update fieldNames(i), fieldValues(i)
next

response.redirect("userdetails_completed.asp"

end if
end if
%>

Reply to this topic