none
error stored procedure RRS feed

  • Question

  •  

    bom dia estou fazendo um teste para executar a stored procedure nao funciona com este codigo

     

     

    create procedure spd_monitoramento @dta_inicial datetime    
                                                          ,@dta_final  datetime    
       
    as   

      select distinct d.uid   
           ,datepart(wk, dta_hora_contato) wk   
           ,ind_categoria   
       into #tmp   
       from tb_dados d   
           ,db_tabela..tb_usuario u   
           ,db_tabela..tb_contrato c   
      where d.uid = u.uid   
        and d.cod_contrato = c.cod_contrato   
        and dta_hora_contato between @dta_inicial and @dta_final   
        and d.uid not in (439)   
        and d.cod_referencia not in (null,'')   
        and d.cod_serv_prestado<>'099'   
        and ind_categoria not in('L','M')  
      order by d.uid   

     select * from #tmp

     

    go

     

     

     

    string d1 = "01/01/2008";

    string d2 = "01/01/2008";

    OdbcCommand command = new OdbcCommand("spd_monitoramento", sBanco.sConn);

    command.CommandType = CommandType.StoredProcedure;

    command.Parameters.Add("@dta_inicial", OdbcType.DateTime).Value = Convert.ToDateTime(d1);

    command.Parameters.Add("@dta_final", OdbcType.DateTime).Value = Convert.ToDateTime(d2);

    OdbcDataAdapter adapter = new OdbcDataAdapter(command);

    //DataSet dtSet = new DataSet();

    adapter.Fill(dtSet, "teste");

    dg.DataSource = dtSet;

    dg.DataBind();

     

     

     

    erro que retorna

     

    ERROR [HY000] [SYBASE][ODBC Sybase driver][SQL Server]Procedure spd_monitoramento expects parameter @dta_inicial, which was not supplied.

    ERROR [HY000] [SYBASE][ODBC Sybase driver][SQL Server]Procedure spd_monitoramento expects parameter @dta_final, which was not supplied.

     

     

    obrigado

    Friday, January 18, 2008 2:30 PM

All replies

  • Hello,

     

    I prefer to separate the definition of parameters and the value setting of parameters

    string d1 = "01/01/2008";

    string d2 = "01/01/2008";

    OdbcCommand command = new OdbcCommand("spd_monitoramento", sBanco.sConn);

    command.CommandType = CommandType.StoredProcedure;

    command.Parameters.Add("@dta_inicial", OdbcType.DateTime);

    command.Parameters.Add("@dta_final", OdbcType.DateTime);

    command.Parameters["@dta_inicial"].Value = Convert.ToDateTime(d1);

    command.Parameters["@dta_final"].Value = Convert.ToDateTime(d2);

    OdbcDataAdapter adapter = new OdbcDataAdapter(command);

    //DataSet dtSet = new DataSet();

    adapter.Fill(dtSet, "teste");

    dg.DataSource = dtSet;

    dg.DataBind();

     

    I don't like have complex instructions in one line.

    I prefer to write more code and help the readibility of the code

     

    I hope it will help you

     

    Have a nice day

    Friday, January 18, 2008 6:00 PM
  • Try:

    command.Parameters.Add("dta_inicial", OdbcType.DateTime).Value = Convert.ToDateTime(d1);

    command.Parameters.Add("dta_final", OdbcType.DateTime).Value = Convert.ToDateTime(d2);

     

    Instead.

     

    Thursday, January 24, 2008 6:28 PM