Problem with ODBC and OUT parameteres using C#
Posted by:
Mark Toth
Date: July 02, 2005 07:51AM
Folks,
I'm having a major problem retrieving OUT parametes in ODBC. I have a stored procedure created like this
delimiter //
CREATE_PROCEDURE sp_CountUsers(OUT param1 INT)
BEGIN
SELECT COUNT(*) INTO param1 FROM users
END
//
delimiter ;
OK I run this procedure like this through the MySQL Command Line Editor
CALL sp_CountUsers(@a);
Then
SELECT @a
and I get the results I expected
----------
@a
----------
2
----------
just like I should so the procedure is working fine
Now I have a C# program that tries to access the stored procedure like this
public void CountUsers()
{
try
{
// see if m_odbcConnection is open already
// if not open it
if( IsOpen == false )
Open();
if( IsOpen )
{
bool ret = false;
string test = "";
m_odbcCommand = new OdbcCommand("CALL sp_CountUsers(?)",
m_odbcConnection );
OdbcParameter param = m_odbcCommand.Parameters.Add( "@param1",
OdbcType.Int);
param.Direction = ParameterDirection.Output;
OdbcDataReader dr = m_odbcCommand.ExecuteReader();
while (dr.Read())
MessageBox.Show(dr.GetString(0));
test = m_odbcCommand.Parameters[0].Value.ToString();
dr.Close();
Close();
}
}
catch( OdbcException dbEx )
{
MessageBox.Show(dbEx.Message);
}
catch( Exception ex )
{
MessageBox.Show(ex.Message);
}
}
The problem is there is nothing in m_odbcCommand.Paramters[0].Value it is DBNull!
and the
while (dr.Read())
MessageBox.Show(dr.GetString(0));
doesn't run at all since there is nothing in the data reader. And I get NO error back from MySQL no exception what so ever so it seems the database is fine with the procedure call but something is being lost in the ODBC connection when it returns????
Can someone help??????????
Subject
Views
Written By
Posted
Problem with ODBC and OUT parameteres using C#
2477
July 02, 2005 07:51AM
1311
July 02, 2005 09:35AM
1393
July 02, 2005 09:40AM
1460
July 02, 2005 09:48AM
1272
January 27, 2006 04:46PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.