locked
how do i add parameter ? RRS feed

  • Question

  • User1270199477 posted

    I am new to Entlib 5.  I am converting my code using ent lib 5.


    here's my code.  how do i add parameter.  I checked hands on lab, it didnt have sample codes for parameters. another qustion,  this "return (SqlDataReader)dr;", should it be inside using statement or after using statement.



            public SqlDataReader GetHospitalsByTaxID(int taxID)
            {
                using (IDataReader dr = _db.ExecuteReader("GetHospitalsByTaxID"))
                {
                    return (SqlDataReader)dr;
                }
    
            //SqlConnection conn = new SqlConnection(_conn);
            //SqlCommand cmd = new SqlCommand();
            //cmd.Connection = conn;
            //cmd.CommandType = CommandType.StoredProcedure;
            //cmd.CommandText = "GetHospitalsByTaxID";
    
    
            //SqlParameter TaxID = new SqlParameter();
            //TaxID.ParameterName = "@taxID";
            //TaxID.SqlDbType = SqlDbType.Int;
            //TaxID.Direction = ParameterDirection.Input;
            //TaxID.Value = taxID;
    
            //cmd.Parameters.Add(TaxID);
    
            //conn.Open();
            //return cmd.ExecuteReader(CommandBehavior.CloseConnection);
            }
    




    Tuesday, February 8, 2011 9:03 PM

Answers

  • User1270199477 posted

    i just figure it out. ExecuteReader allows me to add parameters array to the end.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 9, 2011 3:52 PM

All replies

  • User1415119982 posted

    Create DBCommand using your _db's GetStoredProcCommand method.

    add the parameters using _db.AddInParameter by supplying your earlier DBCommand object and parameter.

    Now Execute the reader method of _db object by supplying the dbcommand object created earlier.

     

    Hope been helpful

     

    Tuesday, February 8, 2011 11:12 PM
  • User1270199477 posted

    i just figure it out. ExecuteReader allows me to add parameters array to the end.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 9, 2011 3:52 PM