1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Is it necessary to set the CommandType to stored procedures?

Discussion in 'C#' started by fluid, Aug 10, 2006.

  1. #1
    i tried to execute a stored procedure using the following syntax:

    SqlConnection con = new SqlConnection(myconstr);
    con.Open();
    /*
    fetch_users is the name of the stored procedure i created in MS SQL Server 2000
    */
    SqlCommand cmd = new SqlCommand("fetch_users", con);
    //cmd.CommandType = CommandType.StoredProcedure;
    SqlDataReader myReader;
    myReader = cmd.ExecuteReader();
    // write the output here
    while (myReader.Read())
    {
    Response.Write(myReader[1]);
    }
    con.Close();
    SEMrush
    As you can see from my codes, i've commented out the cmd.CommandType = CommandType.StoredProcedure;, so does it make any difference at all and should we specify this bit?
     
    fluid, Aug 10, 2006 IP
    SEMrush
  2. fluid

    fluid Active Member

    Messages:
    679
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    70
    #2
    Having done a few more tests, i've got the answer to my own question. If the stored procedure uses parameters, then we need to set the CommandType to StoredProcedure so that the parameters can be passed. If this is not specified, then we'll get a compilation error. But for unparameterised stored procedures, the CommandType is not important!
     
    fluid, Aug 11, 2006 IP