passing parameters using stored procedure with where clause??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hemantc87
    New Member
    • Mar 2010
    • 13

    #1

    passing parameters using stored procedure with where clause??

    i have created this function with a parameter offset and i want to access the database using stored procedure but the code and stored procedure i have written below is not working...what is the right way to do it??

    Code:
    public bool isoffsetexist(int offset)
        {
            conn.Open();
         
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "sp_offset1";
            SqlDataReader dr = cmd.ExecuteReader();
        
            int i = 0;
            while (dr.Read())
            {
                i++;
            }
            if (i == 1)
            {
                conn.Close();
                return true;
            }
            else
            {
                conn.Close();
                return false;
            }
        }
    my stored procedure "sp_offset1 " is

    Code:
    CREATE PROCEDURE [dbo].[sp_offset1]
    @offset numeric,
    @appname varchar(20),
    @os varchar(20)
     AS
    select * from tb_offset
     where @offset=" + offset + "
  • truezplaya
    New Member
    • Jul 2007
    • 115

    #2
    http://www.c-sharpcorner.com/UploadF...eSPwithDP.aspx

    I'm not entirely sure this is what you are looking for but have a look towards the end of the page. It has a little sample of adding parameters

    truez

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      You need to use the SqlCommand.Para meters property to set the variable.

      -Frinny

      Comment

      Working...