PDA

View Full Version : Adding a record to access database!


artfullegac
01-09-2004, 03:59 AM
I've trie about everything and can't get my code to work.

<%
Dim date1
Dim date
Dim time
Dim name
Dim description
Dim cost
Dim status

date1 = Request.Form("date1")
date = Request.Form("date")
time = Request.Form("time")
name = Request.Form("name")
description = Request.Form("description")
cost = Request.Form("cost")
status = Request.Form("status")

Dim adoCon
Dim adoRec
Dim strSQL

adoCon = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\mydb.mdb"))

Set adoRec = Server.CreateObject("ADODB.Recordset")

adoRec.Open "classes",adoCon,adopenstatic,adlockoptimistic
This seems to be the problem.</font id="red">

'adoRec.AddNew

'adoRec.Fields("date1") = "02/04/2004"
'adoRec.Fields("date") = "Feb. 04"
'adoRec.Fields("time") = "10:00pm"
'adoRec.Fields("name") = "Test"
'adoRec.Fields("description") = "description"
'adoRec.Fields("cost") = "$2"
'adoRec.Fields("status") = "All Welcome!"

'adoRec.Update

'adoCon.Close
Set adoCon = Nothing
'adoRec.Close
Set adoRec = Nothing
%>

Any assistance you can provide will be appreciated.

Thanks... Dan

bruce
01-09-2004, 06:08 AM
Why do you want to use a recordset to insert a record?

You can do something simple like this


<%

Dim cnnSimple ' ADO connection
Dim rstSimple ' ADO recordset
Set cnnSimple = Server.CreateObject("ADODB.Connection")


cnnSimple.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\test.mdb"))
cnnSimple.Execute("insert into tblContact (FirstName,LastName,Email) values ('Joe','blow','joeBlow@test.com')")
cnnSimple.close

%>

[b]quote:Originally posted by artfullegac

I've trie about everything and can't get my code to work.

<%
Dim date1
Dim date
Dim time
Dim name
Dim description
Dim cost
Dim status

date1 = Request.Form("date1")
date = Request.Form("date")
time = Request.Form("time")
name = Request.Form("name")
description = Request.Form("description")
cost = Request.Form("cost")
status = Request.Form("status")

Dim adoCon
Dim adoRec
Dim strSQL

adoCon = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\mydb.mdb"))

Set adoRec = Server.CreateObject("ADODB.Recordset")

adoRec.Open "classes",adoCon,adopenstatic,adlockoptimistic
This seems to be the problem.</font id="red">

'adoRec.AddNew

'adoRec.Fields("date1") = "02/04/2004"
'adoRec.Fields("date") = "Feb. 04"
'adoRec.Fields("time") = "10:00pm"
'adoRec.Fields("name") = "Test"
'adoRec.Fields("description") = "description"
'adoRec.Fields("cost") = "$2"
'adoRec.Fields("status") = "All Welcome!"

'adoRec.Update

'adoCon.Close
Set adoCon = Nothing
'adoRec.Close
Set adoRec = Nothing
%>

Any assistance you can provide will be appreciated.

Thanks... Dan
</blockquote id="quote"></font id="quote">

artfullegac
01-09-2004, 06:08 AM
Suspected code was the culprit.

Fix = adoRec.Open strSQL,adoCon,3,3

The integer arguments seemed to fix it.

Thanks... Hope this helps someone.

Dan

artfullegac
01-09-2004, 06:10 AM
Ahhh... I'll lean out my code.

Thanks again.

steurm
01-10-2004, 08:40 AM
You can only use the adopenstatic,adlockoptimistic, ... if they are available. These are constants which need to be defined. Usually they are in a specific file, something like adovbcs.inc, which is then included in every page where you want to have these constants available.

Here is an example file.
[quote]
<scriptrunat="server"language="vbscript">
'----FieldAttributeEnumValues----
ConstadFldUpdatable=&H00000004
ConstadFldUnknownUpdatable=&H00000008
ConstadFldIsNullable=&H00000020

'----CursorTypeEnumValues----
ConstadOpenForwardOnly=0
ConstadOpenKeyset=1
ConstadOpenDynamic=2
ConstadOpenStatic=3

'----Deletetypes----
ConstadAffectCurrent=1
ConstadAffectGroup=2

'----LockTypeEnumValues----
ConstadLockReadOnly=1
ConstadLockPessimistic=2
ConstadLockOptimistic=3
ConstadLockBatchOptimistic=4

'----RecordSetOption
ConstadCmdText=1'EvaluateSourceasatextualdefinitio nofacommand.
ConstadCmdTable=2'EvaluateSourceasatablename.
ConstadCmdStoredProc=4'EvaluateSourceasastoredproc edure.
ConstadCmdUnknown=8'Unknowncommandtype

'----DataTypeEnumValues----
ConstadEmpty=0'Novaluewasspecified
ConstadSmallInt=2'A2-bytesignedinteger
ConstadInteger=3'A4-bytesignedinteger
ConstadSingle=4'Asingle-precisionfloatingpointvalue
ConstadDouble=5'Adouble-precisionfloatingpointvalue
ConstadCurrency=6'Acurrencyvalue(8-bytesignedintegerscaledby10,000)
ConstadDate=7'ADatevalue
ConstadBSTR=8'Anull-terminatedcharacterstring(Unicode)
ConstadIDispatch=9'ApointertoanIDispatchinterfaceo nanOLEobject
ConstadError=10'A32-biterrorcode
ConstadBoolean=11'ABooleanvalue
ConstadVariant=12'AnOLEAutomationVariant
ConstadIUnknown=13'ApointertoanIUnknowninterfaceon anOLEobject
ConstadDecimal=14'Anexactnumericvaluewithafixedpre cisionandscale
ConstadTinyInt=16'A1-bytesignedinteger
ConstadUnsignedTinyInt=17'A1-byteunsignedinteger
ConstadUnsignedSmallInt=18'A2-byteunsignedinteger
ConstadUnsignedInt=19'A4-byteunsignedinteger
ConstadBigInt=20'An8-bytesignedinteger
ConstadUnsignedBigInt=21'An8-byteunsignedinteger
ConstadGUID=72'Agloballyuniqueidentifier(GUID)
ConstadBinary=128'Abinaryvalue
ConstadChar=129'AStringvalue
ConstadWChar=130'Anull-terminatedUnicodecharacterstring
ConstadNumeric=131'Anexactnumericvaluewithafixedpr ecisionandscale
ConstadUserDefined=132'Auser-definedvariable
ConstadBDDate=133'Adatevalue(yyyymmdd)
ConstadDBTime=134'Atimevalue(hhmmss)
ConstadDBTimeStamp=135'Adate-timestamp(yyyymmddhhmmssplusafractioninbillionths)
ConstadVarChar=200'AStringvalue(Parameterobjectonl y)
ConstadLongVarChar=201'AlongStringvalue(Parametero bjectonly)
ConstadWVarChar=202'Anull-terminatedUnicodecharacterstring(Parameterobjecton ly)
ConstadLongVarWChar=203'Alongnull-terminatedstringvalue(Parameterobjectonly)
ConstadVarBinary=204'Abinaryvalue(Parameterobjecto nly)
ConstadLongVarBinary=205'Alongbinaryvalue(Paramete robjectonly)

'----CursorLocationEnumValues----
ConstadUseServer=2
ConstadUseClient=3


//-->

</script></CODE>

--
Steurm
www.steurm.net/steurm