sql parameter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MikeJ

    sql parameter

    example below can we get a parameter by name or have to use the indexOf

    SqlCommand cmd = new SqlCommand("pro c_ERRORLOG_INSE RT", oConn);

    cmd.CommandType = CommandType.Sto redProcedure;

    SqlParameter param = new SqlParameter();

    cmd.Parameters. Add("@Fileid", SqlDbType.Int). Value=99999;

    cmd.Parameters. Add("@ErrorMess age", SqlDbType.VarCh ar).Value="Serv ice Failed
    on APP Server1";

    cmd.Parameters. Add("@Retvalue" ,
    SqlDbType.Int). Direction=Param eterDirection.O utput;

    int iret = cmd.ExecuteNonQ uery();

    Console.WriteLi ne("return value "+iret.ToString ()); //iRet is Rows
    Affected

    Console.WriteLi ne(cmd.Paramete rs.IndexOf("@Re tvalue")); // Proc Return
    Number (value)

    console.Read();

    how can i get the @retvalue by name , Not by its index position in the
    collection



    TIA MJ






  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: sql parameter

    MikeJ,

    You should be able to do:

    SqlParameter = cmd.Parameters["@retvalue"];

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "MikeJ" <vettes_n_jets@ yahoo.comwrote in message
    news:eQ7Th.7831 $u03.1078@newss vr21.news.prodi gy.net...
    example below can we get a parameter by name or have to use the indexOf
    >
    SqlCommand cmd = new SqlCommand("pro c_ERRORLOG_INSE RT", oConn);
    >
    cmd.CommandType = CommandType.Sto redProcedure;
    >
    SqlParameter param = new SqlParameter();
    >
    cmd.Parameters. Add("@Fileid", SqlDbType.Int). Value=99999;
    >
    cmd.Parameters. Add("@ErrorMess age", SqlDbType.VarCh ar).Value="Serv ice
    Failed on APP Server1";
    >
    cmd.Parameters. Add("@Retvalue" ,
    SqlDbType.Int). Direction=Param eterDirection.O utput;
    >
    int iret = cmd.ExecuteNonQ uery();
    >
    Console.WriteLi ne("return value "+iret.ToString ()); //iRet is Rows
    Affected
    >
    Console.WriteLi ne(cmd.Paramete rs.IndexOf("@Re tvalue")); // Proc Return
    Number (value)
    >
    console.Read();
    >
    how can i get the @retvalue by name , Not by its index position in the
    collection
    >
    >
    >
    TIA MJ
    >
    >
    >
    >
    >
    >

    Comment

    • Alberto Poblacion

      #3
      Re: sql parameter

      "MikeJ" <vettes_n_jets@ yahoo.comwrote in message
      news:eQ7Th.7831 $u03.1078@newss vr21.news.prodi gy.net...
      how can i get the @retvalue by name , Not by its index position in the
      collection
      cmd.Parameters["@retvalue"] should work.


      Comment

      • MikeJ

        #4
        Re: sql parameter

        Thank you
        MJ

        "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote in
        message news:%232J2wVFf HHA.1312@TK2MSF TNGP03.phx.gbl. ..
        MikeJ,
        >
        You should be able to do:
        >
        SqlParameter = cmd.Parameters["@retvalue"];
        >
        Hope this helps.
        >
        >
        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m
        >
        "MikeJ" <vettes_n_jets@ yahoo.comwrote in message
        news:eQ7Th.7831 $u03.1078@newss vr21.news.prodi gy.net...
        >example below can we get a parameter by name or have to use the indexOf
        >>
        >SqlCommand cmd = new SqlCommand("pro c_ERRORLOG_INSE RT", oConn);
        >>
        >cmd.CommandTyp e = CommandType.Sto redProcedure;
        >>
        >SqlParameter param = new SqlParameter();
        >>
        >cmd.Parameters .Add("@Fileid", SqlDbType.Int). Value=99999;
        >>
        >cmd.Parameters .Add("@ErrorMes sage", SqlDbType.VarCh ar).Value="Serv ice
        >Failed on APP Server1";
        >>
        >cmd.Parameters .Add("@Retvalue ",
        >SqlDbType.Int) .Direction=Para meterDirection. Output;
        >>
        >int iret = cmd.ExecuteNonQ uery();
        >>
        >Console.WriteL ine("return value "+iret.ToString ()); //iRet is Rows
        >Affected
        >>
        >Console.WriteL ine(cmd.Paramet ers.IndexOf("@R etvalue")); // Proc Return
        >Number (value)
        >>
        >console.Read() ;
        >>
        >how can i get the @retvalue by name , Not by its index position in the
        >collection
        >>
        >>
        >>
        >TIA MJ
        >>
        >>
        >>
        >>
        >>
        >>
        >
        >

        Comment

        • MikeJ

          #5
          Re: sql parameter

          here is a piece of my code...the parameter fileid is not returning
          SqlCommand Cmd = new SqlCommand("oa_ SERVICE_OA2_get FileToProcess",
          oConnect);

          Cmd.CommandType = CommandType.Sto redProcedure;

          Cmd.CommandTime out = 600;

          Cmd.Parameters. Add("Statusid", SqlDbType.Int). Value = 123; //Direction =
          ParameterDirect ion.Input;

          Cmd.Parameters. Add("FormTypeid ", SqlDbType.Int). Value = 2;//Direction =
          ParameterDirect ion.Input;

          Cmd.Parameters. Add("SetStatusI dTo", SqlDbType.Int). Value = 139; //Direction
          = ParameterDirect ion.Input;

          Cmd.Parameters. Add("FileId", SqlDbType.Int). Direction =
          ParameterDirect ion.Output;

          Cmd.Parameters. Add("FilePath", SqlDbType.VarCh ar,244).Directi on =
          ParameterDirect ion.Output;

          Cmd.Parameters. Add("ReturnCode ", SqlDbType.Int). Direction =
          ParameterDirect ion.ReturnValue ;

          int iRet = Cmd.ExecuteNonQ uery();

          Console.WriteLi ne(Cmd.Paramete rs["ReturnCode "].Value); //shows
          correct value

          Console.WriteLi ne(Cmd.Paramete rs["Fileid"].Value); //shows
          empty

          Console.WriteLi ne(Cmd.Paramete rs["FilePath"].Value); //Empty

          Console.WriteLi ne("Ret {0}", iRet.ToString() ); // Shows
          Correct Value

          Console.Read();


          Tia
          MJ




          "Alberto Poblacion" <earthling-quitaestoparaco ntestar@poblaci on.orgwrote
          in message news:%23uIvHYFf HHA.2640@TK2MSF TNGP06.phx.gbl. ..
          "MikeJ" <vettes_n_jets@ yahoo.comwrote in message
          news:eQ7Th.7831 $u03.1078@newss vr21.news.prodi gy.net...
          >how can i get the @retvalue by name , Not by its index position in the
          >collection
          >
          cmd.Parameters["@retvalue"] should work.
          >
          >

          Comment

          • Alberto Poblacion

            #6
            Re: sql parameter

            "MikeJ" <vettes_n_jets@ yahoo.comwrote in message
            news:T3eTh.7788 $Kd3.6766@newss vr27.news.prodi gy.net...
            here is a piece of my code...the parameter fileid is not returning
            [...]
            Cmd.Parameters. Add("FileId", SqlDbType.Int). Direction = [...]
            Console.WriteLi ne(Cmd.Paramete rs["Fileid"].Value);
            //shows empty
            I suspect a casing problem: you are creating the parameter as "FileId"
            (uppercase "I") and then looking for "Fileid" (lowercase "i").


            Comment

            Working...