Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem with passing parameter to MySQL Stored Procedure

Posted on 2009-05-14
4
Medium Priority
?
792 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

721 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