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(); 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?
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!