|
-
Aug 14th, 2007, 09:36 AM
#1
Thread Starter
New Member
Must declare the scalar variable
Hello,
I try to put an image into a sql db, and i think i am close but now i still get the message
[Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the scalar variable "@FORM_SCAN".
How can i declare this variable? When i try to do this in sql db it tells me
The text, ntext, and image data types are invalid for local variables.
How can i solve this?
Code:
Dim mStream As New ADODB.Stream
With mStream
.Type = adTypeBinary
.Open
.LoadFromFile TheData.ImageFiles.ReleasedDirectory
End With
Dim MyParameter As ADODB.Parameter
'Set MyParameter = cmd.CreateParameter("rows", adInteger, adParamOutput)
Set MyParameter = cmd.CreateParameter("@FORM_SCAN", adLongVarBinary, adParamInput, mStream.Size)
cmd.Parameters.Append MyParameter
cmd.ActiveConnection = cnn
cmd.CommandText = "INSERT INTO deelnemer_aanw_scan VALUES (" & sbatchID & ", @FORM_SCAN)"
cmd.Parameters(0).Value = mStream.Read
cmd.Execute
-
Aug 14th, 2007, 10:20 AM
#2
Re: Must declare the scalar variable
You need to set the CommandText before adding parameters.
Note that there is a tutorial in our Database FAQs which does something similar - it may contain useful info for you.
-
Aug 14th, 2007, 10:31 AM
#3
Re: Must declare the scalar variable
Does the ODBC provider support named parameters? Try setting the NamedParameters property of the Command object to True or change the insert statement to
cmd.CommandText = "INSERT INTO deelnemer_aanw_scan VALUES (" & sbatchID & ", ?)"
-
Aug 14th, 2007, 12:00 PM
#4
Thread Starter
New Member
Re: Must declare the scalar variable
Hi,
Tried your suggestions only with the same result.
Code:
Dim mStream As New ADODB.Stream
With mStream
.Type = adTypeBinary
.Open
.LoadFromFile TheData.ImageFiles.ReleasedDirectory
End With
Dim MyParameter As ADODB.Parameter
'Set MyParameter = cmd.CreateParameter("rows", adInteger, adParamOutput)
Set MyParameter = cmd.CreateParameter("@FORM_SCAN", adLongVarBinary, adParamInput, mStream.Size)
cmd.NamedParameters = True
cmd.CommandText = "INSERT INTO deelnemer_aanw_scan VALUES (" & sbatchID & ", @FORM_SCAN)"
cmd.Parameters.Append MyParameter
cmd.ActiveConnection = cnn
cmd.Parameters(0).Value = mStream.Read
cmd.Execute
-
Aug 14th, 2007, 12:38 PM
#5
Re: Must declare the scalar variable
NamedParameters might only be supported with Stored Procedures or specific Providers. Did you try using the ? as the parameter placeholder? That should work no matter the provider.
-
Aug 14th, 2007, 01:24 PM
#6
Thread Starter
New Member
Re: Must declare the scalar variable
Can u pleae tell me how this works? I mean should i work these ? in order of parameter in the sql statement. Something like this
insert into table values ( ? , ? ) = insert into table values ( parameter1 , parameter2 )
-
Aug 14th, 2007, 01:32 PM
#7
Re: Must declare the scalar variable
A parameter must be added to the parameters collection in the order they appear in the sql statement. So cmd.Parameters(0) applies to the first ?, cmd.Parameters(1) to the second and so on...
-
Aug 14th, 2007, 02:34 PM
#8
Thread Starter
New Member
Re: Must declare the scalar variable
It seems to work perfectly, tomorrow i will do some more testing with it. But i allready could read an image inside the sql db.
Thank you all for the help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|