The stored procedure is as follows:
Create procedure testsp
@ ID int
As
Return @ Error
Go
Online examples use SQL objects to transmit parameters, so they are written in the same format.CodeThe result cannot contain parameters. The Code is as follows:
Try
{
Odbcconnection m_cconn = new odbcconnection ();
Odbccommand m_ccommand = new odbccommand ();
Odbcparameter cparam = new odbcparameter ("@ ID", odbctype. Int, 4 );
M_cconn.connectionstring = "DSN = mysqlserver; trusted_connection = yes; wsid = binarytree; database = simpleprojectdb ";
M_cconn.open ();
M_ccommand.connection = m_cconn;
M_ccommand.commandtext = "testsp ";
M_ccommand.commandtype = commandtype. storedprocedure;
M_ccommand.parameters.add (cparam );
M_ccommand.executenonquery ();
}
Catch (exception cex)
{
Return;
}
When the above Code runs to m_ccommand.executenonquery (); An exception occurs, saying that the parameter is not found. The problem lies in the commandtext attribute setting. The correct format should be as follows:
M_ccommand.commandtext = "{call testsp (?)} ";