ADODB.Command

babban
babban used Ask the Experts™
on
Hi.

The code is posted first, question(s) at the end.

<%

<!-- #include file="ADOVBS.INC" -->

sEngelska = "dog"
sSvenska = "hund"
iVecka = 50
sElev = "Babban"

Set objCommand = Server.CreateObject("ADODB.Command")

'Tilldela objectet objCommand anslutning till MS Access databas

objCommand.ActiveConnection = "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\Inetpub\wwwroot\test.mdb"

'Engelska, Svenska, Vecka, Elev
objCommand.CommandText = "INSERT INTO tblGlosor (Id, Engelska, Svenska, Vecka, Elev) VALUES (?,?,?,?,?)"

Set prmNew = objCommand.CreateParameter(,adInteger,,,Id)
objCommand.Parameters.Append prmNew

Set prmNew = objCommand.CreateParameter(,adVarChar,,50,sEngelska)
objCommand.Parameters.Append prmNew

Set prmNew = objConnection.CreateParameter(,adVarChar,,50,sSvenska)
objCommand.Parameters.Append prmNew

Set prmNew = objCommand.CreateParameter(,adInteger,,,iVecka)
objCommand.Parameters.Append prmNew

Set prmNew = objCommand.CreateParameter(,adVarChar,,50,sElev)
objCommand.Parameters.Append prmNew

objCommand.Execute RecordsAffected,,adCmdText

%>

QUESTION(S)

a) My first try to create a parameter is on the field 'Id'. That is an auto number field in Access. Can I select the constant adInteger to that field?

b) 'Engelska' is my second parameter, and that is a text field in Access. Is adVarChar correct constan for this?

c) I have also set the field lenght for 'Engelska' to 50 and that is the same length I have set in the Access table/field itself. What happens if the lenght doesn't match?

d) I recive an error message when I run this code:
Error Type:
ADODB.Parameters (0x800A0E7C)
Parameter object is improperly defined. Inconsistent or incomplete information was provided.
/Commandtest.asp, line 23

What is wrong?

Greatest Regards

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
Commented:
a) If you have an Autonumber field, DON'T insert data to that field:
objCommand.CommandText = "INSERT INTO tblGlosor ( Engelska, Svenska, Vecka, Elev) VALUES (?,?,?,?)"

b+c) yes. If the lengthe doesn't match, you might get an error when running the command. This depends on wether the lenght supplied is longer than the actual size or not...

d) could be because of a), but also because you didn't supply any name to the parameters... not sure thoug about the name

CHeers

Author

Commented:
How do I supply a name to a parameter? How sould the line look?
Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
The name for the parameter is the first argument in the CreateParameter function...
Set prmNew = objCommand.CreateParameter("sEngelska",adVarChar,,50,sEngelska)
objCommand.Parameters.Append prmNew
Again, not sure if THAT helps, because I cannot test it right now...
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Author

Commented:
Ok.
What argument is meant to be after adVarchar ?
I have only a pocket book about ASP 3.0
Can't find the arguments there.
Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
CreateParameter (name, type, direction, size, value)
the direction can be
adParamUnkown (0)
adParamInput (1)
adParamOutput (2)
adParamInputOuput (3)
adParamReturn (4)

For your query, you either use adParamUnknown (default value), or adParamInput (1)

CHeers

Commented:
the arguments after adVarchar are as any of the following:


  adParamInput
  adParamInputOutput
  adParamOutput
  adParamReturnValue
  adParamUnknown

Commented:
like whoa.. guess i should reload the question before waking up later and hitting post, lol

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial