none
使用ODBC访问sybase数据库,调用存储过程,总是报错没有第一个参数,请问是什么原因? RRS feed

  • 问题

  •    using (OdbcConnection conn = new  OdbcConnection(connectionString))
                {
                    OdbcCommand cmd = new OdbcCommand("sp_get_advanced_serial_number", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    //cmd.Parameters.AddWithValue("@table_name", "ivr_task");
                    //cmd.Parameters.Add("@RecordID", OdbcType.VarChar,20).Direction = ParameterDirection.Output;

                    OdbcParameter p1 = new OdbcParameter("@table_name", OdbcType.VarChar, 20);
                    p1.Direction = ParameterDirection.Input;
                    p1.Value = "ivr_task";
                    cmd.Parameters.Add(p1);
                    OdbcParameter p2 = new OdbcParameter("@RecordID", OdbcType.VarChar, 20);
                    p2.Direction = ParameterDirection.Output;
                    cmd.Parameters.Add(p2);
                    try
                    {
                        conn.Open();
                        cmd.ExecuteNonQuery();
                        d_serial = (decimal)cmd.Parameters["@RecordID"].Value;
                    }
                    catch (OdbcException ex)
                    {
                        status.Text = ex.Message+ "警告:调用ivr_task流水号失败!";//terminal_reimbursement
                        return;
                    }
                    finally
                    {
                        conn.Close();
                    }
                }

    存储过程如下


    create   procedure [dbo].[sp_get_advanced_serial_number]
      @table_name varchar(60) ,
      @RecordID varchar(20) output
    as
    begin
     declare
      @yearmonth varchar(20) ,
      @new_yearmonth varchar(20) ,
      @num  integer,
      @ID decimal(38, 0) 
      
     select @yearmonth=convert(char(7),getdate(),20)
     select @new_yearmonth=REPLACE(@yearmonth,'-','')
     SET   XACT_ABORT   ON
     begin tran
       select @num=COUNT(1) from advanced_serial_number where table_name=@table_name and yearmonth=@yearmonth
       if (@num=0)
        begin
         insert  advanced_serial_number values(@table_name,@yearmonth,0)
         select @ID =0
        end
       else
        begin
         update advanced_serial_number set id=id+1 where table_name=@table_name and yearmonth=@yearmonth
         select @ID =id from advanced_serial_number where table_name=@table_name and yearmonth=@yearmonth
        end 
       
       print @yearmonth
       print @ID
      commit  tran
     select @RecordID=@new_yearmonth+right('00000'+convert(varchar(10),@ID),6)
     print @RecordID
     return 0
    end

    2014年2月20日 9:19

答案

全部回复