我在C#里调用firebird 存储过程报错 现在贴出来求高手指点:

蒙哥铁穆耳 发布于 2011/08/15 10:28
阅读 776
收藏 0

————————————————存储过程——————————————————————

 
CREATE PROCEDURE PR_COACCOUNT_SUM (
    ORDERDATEBEG DATE,
    ORDERDATEEND DATE,
    SECTOR VARCHAR(20),
    COSTOBJECT VARCHAR(20))
RETURNS (
    SUMCOUNT VARCHAR(6))
AS
DECLARE VARIABLE T_SUM INTEGER;
BEGIN
  select sum((SELLSUM+SERVICESUM)-SELLCOSTSUM)
  from tb_coaccount
  where COSTOBJECT=:costobject and SECTOR=:sector and ORDERDATE <= :orderdateend
  and ORDERDATE >= :orderdatebeg
  INTO :t_sum;
  SUMCOUNT=t_sum;
  SUSPEND;
END
01 CREATE PROCEDURE PR_COACCOUNT_SUM (
02     ORDERDATEBEG DATE,
03     ORDERDATEEND DATE,
04     SECTOR VARCHAR(20),
05     COSTOBJECT VARCHAR(20))
06 RETURNS (
07     SUMCOUNT VARCHAR(6))
08 AS
09 DECLARE VARIABLE T_SUM INTEGER;
10 BEGIN
11   select sum((SELLSUM+SERVICESUM)-SELLCOSTSUM)
12   from tb_coaccount
13   where COSTOBJECT=:costobject and SECTOR=:sector and ORDERDATE <= :orderdateend
14   and ORDERDATE >= :orderdatebeg
15   INTO :t_sum;
16   SUMCOUNT=t_sum;
17   SUSPEND;
18 END

————————————————C#———————————————————————————

FbCommand comm;
FbCommand commcount;
FbDataReader fdr;
FbConnection cn = new FbConnection();
cn.ConnectionString = FbServer.GetConnectionString();
cn.Open();

comm = new FbCommand("PR_COACCOUNT_SUM", cn);
comm.CommandType = System.Data.CommandType.StoredProcedure;
//添加输入查询参数、赋予值
comm.Parameters.Add(new FbParameter(":COSTOBJECT", FbDbType.VarChar));
comm.Parameters[":COSTOBJECT"].Value = CostOjbect;
comm.Parameters.Add(new FbParameter(":SECTOR", FbDbType.VarChar));
comm.Parameters[":SECTOR"].Value = ProfitSector;
comm.Parameters.Add(new FbParameter(":ORDERDATEBEG", FbDbType.Date));
comm.Parameters[":ORDERDATEBEG"].Value = ProfitBegDate;
comm.Parameters.Add(new FbParameter(":ORDERDATEEND", FbDbType.Date));
comm.Parameters[":ORDERDATEEND"].Value = ProfitEndDate;
//添加输出参数
comm.Parameters.Add(":SUMCOUNT", FbDbType.VarChar);
comm.Parameters[":SUMCOUNT"].Direction = System.Data.ParameterDirection.Output;
try
{
    comm.ExecuteNonQuery();//到这步报错
}
catch (FbException ex)
{
    MessageBox.Show(ex.Message);
}
 
 
01 FbCommand comm;
02 FbCommand commcount;
03 FbDataReader fdr;
04  
05 FbConnection cn = new FbConnection();
06 cn.ConnectionString = FbServer.GetConnectionString();
07 cn.Open();
08  
09  
10 comm = new FbCommand("PR_COACCOUNT_SUM", cn);
11 comm.CommandType = System.Data.CommandType.StoredProcedure;
12 //添加输入查询参数、赋予值
13 comm.Parameters.Add(new FbParameter(":COSTOBJECT", FbDbType.VarChar));
14 comm.Parameters[":COSTOBJECT"].Value = CostOjbect;
15  
16 comm.Parameters.Add(new FbParameter(":SECTOR", FbDbType.VarChar));
17 comm.Parameters[":SECTOR"].Value = ProfitSector;
18  
19 comm.Parameters.Add(new FbParameter(":ORDERDATEBEG", FbDbType.Date));
20 comm.Parameters[":ORDERDATEBEG"].Value = ProfitBegDate;
21  
22 comm.Parameters.Add(new FbParameter(":ORDERDATEEND", FbDbType.Date));
23 comm.Parameters[":ORDERDATEEND"].Value = ProfitEndDate;
24  
25 //添加输出参数
26 comm.Parameters.Add(":SUMCOUNT", FbDbType.VarChar);
27 comm.Parameters[":SUMCOUNT"].Direction = System.Data.ParameterDirection.Output;
28 try
29 {
30     comm.ExecuteNonQuery();//到这步报错
31 }
32 catch (FbException ex)
33 {
34     MessageBox.Show(ex.Message);
35 }
01 FbCommand comm;
02 FbCommand commcount;
03 FbDataReader fdr;
04  
05 FbConnection cn = new FbConnection();
06 cn.ConnectionString = FbServer.GetConnectionString();
07 cn.Open();
08  
09  
10 comm = new FbCommand("PR_COACCOUNT_SUM", cn);
11 comm.CommandType = System.Data.CommandType.StoredProcedure;
12 //添加输入查询参数、赋予值
13 comm.Parameters.Add(new FbParameter(":COSTOBJECT", FbDbType.VarChar));
14 comm.Parameters[":COSTOBJECT"].Value = CostOjbect;
15  
16 comm.Parameters.Add(new FbParameter(":SECTOR", FbDbType.VarChar));
17 comm.Parameters[":SECTOR"].Value = ProfitSector;
18  
19 comm.Parameters.Add(new FbParameter(":ORDERDATEBEG", FbDbType.Date));
20 comm.Parameters[":ORDERDATEBEG"].Value = ProfitBegDate;
21  
22 comm.Parameters.Add(new FbParameter(":ORDERDATEEND", FbDbType.Date));
23 comm.Parameters[":ORDERDATEEND"].Value = ProfitEndDate;
24  
25 //添加输出参数
26 comm.Parameters.Add(":SUMCOUNT", FbDbType.VarChar);
27 comm.Parameters[":SUMCOUNT"].Direction = System.Data.ParameterDirection.Output;
28 try
29 {
30     comm.ExecuteNonQuery();//到这步报错
31 }
32 catch (FbException ex)
33 {
34     MessageBox.Show(ex.Message);
35 }

单独在数据库里执行存储过程无错

C#comm.ExecuteNonQuery();//到这步报错
求解决

加载中
0
张明华
command.Parameters.Add(new SqlParameter("ReturnValue", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, 0, 0, string.Empty, DataRowVersion.Default, null));

请参考
返回顶部
顶部