passing parameters with help of stored procedure??

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

    passing parameters with help of stored procedure??

    i created a function give below and passed a parameter to it.i used a simple query to access the database..is there any way to do it with a stored procedure with parameters instead of a simple query as stored procedure is a better method

    Code:
    public bool isoffsetexist(int offset)
        {
            conn.Open();
    
            SqlCommand cmd = new SqlCommand("select * from tb_offset where offset= " + offset + "", conn);
    
            /*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;
            }
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    It looks like you've commented out the code that uses the stored procedure....

    Please review the following article that outline how to use a database:
    Database tutorial Part 1
    Database tutorial Part 2

    -Frinny

    Comment

    • hemantc87
      New Member
      • Mar 2010
      • 13

      #3
      the comments were put there by mistake...dont consider them in the code
      thnku frinavale but i still havent got the exact method how to achieve it??

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Well the code that you have in comments uses the stored procedure....so you're going to want to uncomment that.

        To supply parameters to the stored procedure you use the SqlCommand.Para meters.

        -Frinny

        Comment

        Working...