SqlCommand cmd = new SqlCommand(procName,Conn);
cmd.CommandType = CommandType.StoredProcedure;

解决方案 »

  1.   

    write the codes like below (I prefer to the code-behind file .aspx.cs):SqlConnection conn = new SqlConnection(strConnect); //get the connection object
    SqlCommand cmd = new SqlCommand("Check_MailList",conn);
    SqlParameter para = new SqlParameter("@Email",SqlDbType.NVarChar);
    para.Value = txtMail.Text;
    cmd.Parameters.Add(para);//define the parameters of the command object
    para = new SqlParameter("@RecordCount",SqlDbType.Bit);
    para.Direction = ParameterDirection.Output;
    cmd.Parameters.Add(para);
    try
    {
     conn.Open();//open the connection
     cmd.ExecuteNonQuery();//execute the stored procedure
     if ((bool)para["@RecordCount"])//the output value can be got now
     {
      //exist the record,do nothing
     }
     else
     {
      //do insert operation
     }
    }
    catch(Exception x)
    {
     //do something to handle the exception
     throw(x); //continue throwing the exception
    }
    finally
    {
     //do some cleanning work
     if (conn.State == ConnectionState.Open)
     {
      conn.close();
     }
    }
      

  2.   

    sorry,I forget to set the CommandType property :(cmd.CommandType = CommandType.StoredProcedure;