Solved

Problem with passing parameter to MySQL Stored Procedure

Posted on 2009-05-14
4
790 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses

631 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