Solved

Problem with passing parameter to MySQL Stored Procedure

Posted on 2009-05-14
4
785 Views
Last Modified: 2013-12-25
I am using VWD 2005 Express and MySQL 5.1.34

I have tried some very simple stored procedures to test them in MySQL.

Stored Procedures with no parameters are OK, but when I try to execute one with a parameter it is throwing an exceptions as follows :

ex      {"ERROR [HY000] [MySQL][ODBC 3.51 Driver][mysqld-5.1.34]
Incorrect number of arguments for PROCEDURE vehiclereg.getRegistrationDetails;
expected 1, got 0"}      System.Exception

I am using ODBC 3.51 - I understand that MySQL Connector Net 5.2.6 does not work with VWD Express.

The SP works correctly with a parameter when I use the console in MySQL :
mysql> CALL getRegistrationDetails('ABC');

Any help gratefully received as this is driving me crazy !

Ross

VB Code
 
 
        Dim myPar As OdbcParameter
        Dim cmd As New OdbcCommand()
 
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "{ CALL getRegistrationDetails}"
        cmd.Connection = con
 
        myPar = cmd.CreateParameter()
        myPar.ParameterName = "passRegLetters"
        myPar.Value = "ABC"
        myPar.Direction = ParameterDirection.Input
 
        cmd.Parameters.Add(myPar)
 
        Try
            Dim rdr As OdbcDataReader = cmd.ExecuteReader()
            Return rdr
        Catch ex As Exception
            Console.WriteLine("Error: " & ex.ToString())
        End Try
 
 
MySQL Stored Procedure
 
 
select * from regLetters 
	where letters = passRegLetters

Open in new window

0
Comment
Question by:arossco
  • 3
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 24383504
Seen somewhere on another forum, I don't know if it can help you.
There pass this as parameter
cmd.Parameters.Add("?channelID", "2").Direction = ParameterDirection.Input

So can you try one of the following:
1. myPar = cmd.CreateParameter()
        myPar.ParameterName = "?passRegLetters"
        myPar.Value = "ABC"
        myPar.Direction = ParameterDirection.Input
Or
cmd.Parameters.Add("?passRegLetters","ABC")
0
 

Author Comment

by:arossco
ID: 24383693
Thanks - I've tried this and I get exactly the same result.  !

Ross
0
 

Author Comment

by:arossco
ID: 24383703
.. To clarify, I still get :

ex      {"ERROR [HY000] [MySQL][ODBC 3.51 Driver][mysqld-5.1.34]
Incorrect number of arguments for PROCEDURE vehiclereg.getRegistrationDetails;
expected 1, got 0"}      System.Exception

Ross
0
 

Accepted Solution

by:
arossco earned 0 total points
ID: 24384409
Delighted to say that I have solved the problem !

I said in my initial post "I am using ODBC 3.51 - I understand that MySQL Connector Net 5.2.6 does not work with VWD Express" - I guess I was misinformed !

I retried the MySQL Connector which now works - I didn't realise before that I should have been using
MySqlConnection, MySqlCommand etc instead of SqlConnection and SqlCommand etc.

 Ross
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question