CREATE PROCEDURE test
@iCount integer,
@dtModifyTime datetime,
@dcQuantity decimal(20,2) Output
AS
.....
在程序中调用这个存储过程,代码如下
try
{
OdbcCommand cmd = new OdbcCommand();
cmd.Connection = dbconnection;
cmd.CommandText = "test";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@iCount",OdbcType.Int);
cmd.Parameters[0].Value = 10;
cmd.Parameters.Add("@dtModifyTime",OdbcType.DateTime);
cmd.Parameters[1].Value = Convert.ToDateTime("2005-2-25 00:00:00");
cmd.Parameters.Add("@dcQuantity",OdbcType.Numeric);
cmd.Parameters[2].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
float num = (float)cmd.Parameters["dcQuantity"].Value;
MessageBox.Show(num.ToString());
}
catch(OdbcException oe)
{
MessageBox.Show(oe.Message);
}
程序执行到cmd.ExecuteNonQuery();会抛出异常
ERROR [HY000] [INTERSOLV][ODBC SQL Server driver][SQL Server]Procedure up_shizeLastBm expects parameter @iCount, which was not supplied.
ERROR [HY000] [INTERSOLV][ODBC SQL Server driver][SQL Server]Procedure up_shizeLastBm expects parameter @dtModifyTime, which was not supplied.
ERROR [HY000] [INTERSOLV][ODBC SQL Server driver][SQL Server]Procedure up_shizeLastBm expects parameter @dcQuantity, which was not supplied.
需要改为:
DateTime dt = new DateTime(2005,1,10);
OdbcCommand cmd = new OdbcCommand();
cmd.Connection = dbconnection;
cmd.CommandText = "test ?,?,?";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@iCount",OdbcType.Int);
cmd.Parameters[0].Value = 10;
cmd.Parameters.Add("@dtModifyTime",OdbcType.DateTime);
cmd.Parameters[1].Value = dt;
cmd.Parameters.Add("@dcQuantity",OdbcType.Double);
cmd.Parameters[2].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
double num = Convert.ToDouble(cmd.Parameters[3].Value);
MessageBox.Show(num.ToString());
本文地址:http://com.8s8s.com/it/it41700.htm