Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have error on run time "Must declare the scalar variable Error"
how i can solve it ?

this is my function
---------------------

VB
Public Function executeUpdateQuery(ByVal _query As [String], ByVal OleDbParameter As OleDbParameter()) As Boolean
       Dim myCommand As New OleDbCommand()
       Try
           myCommand.Connection = openConnection()
           myCommand.CommandText = _query
           myCommand.Parameters.AddRange(OleDbParameter)
           myAdapter.UpdateCommand = myCommand

           myCommand.ExecuteNonQuery()



       Catch e As SqlException
           MsgBox("Error - Connection.executeUpdateQuery - Query: " & _query & " " & vbLf & "Exception: " & e.StackTrace.ToString())
           Return False
       End Try
       Return True
   End Function
Posted
Comments
Richard MacCutchan 18-Aug-13 7:29am    
Show the values of the command and variables.
Ahmad Al Halabi 18-Aug-13 7:35am    
My Error in "myCommand.ExecuteNonQuery()" >>
myCommand.ExecuteNonQuery() Run-time exception thrown : System.Data.OleDb.OleDbException - Must declare the scalar variable "@ImageData".

---------------------------------------------------------------------------
_query : update Company set CompanyLogo = (@ImageData) where CompanyID = 1
OleDbParameter : length=1
name =@ImageData
value={System.Array}
myCommand : update Company set CompanyLogo = (@ImageData) where CompanyID = 1

1 solution

I Found the Solution

SQL
Replace my named parameters with "?"
for example:
SELECT COUNT(*) FROM Account WHERE AccountID = ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900