passing parameters using stored procedure with where clause??

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

    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 + "
Working...