maybe there is some caching involved, try    SqlCommand cmd = new SqlCommand(procName, con);
    cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Clear();
    cmd.Parameters.Add(pram);
    cmd.ExecuteNonQuery();

解决方案 »

  1.   

    TO  saucer(思归/MVP)没有用呀,问题还是存在!
      

  2.   

    如果我把Page_Load中的
    SqlParameter param = new SqlParameter("@Id", SqlDbType.Int);
    param.Value = 1;移动到RunProc中,就不会有错误发生了!
      

  3.   

    SqlCommand cmd = new SqlCommand(procName, con);
        cmd.CommandType = CommandType.StoredProcedure;    cmd.Parameters.Add(pram);
        cmd.ExecuteNonQuery();    con.Close();
    cmd.Parameters.Clear();
      

  4.   

    TO  saucer(思归/MVP) 还是不行呀,为什么会有这么奇怪的问题呢!
    另:
    如果我把Page_Load中的
    SqlParameter param = new SqlParameter("@Id", SqlDbType.Int);
    param.Value = 1;移动到RunProc中,就不会有错误发生了!
      

  5.   

    SqlParameter cannot belong to multiple Command.Parameters>>移动到RunProc中,就不会有错误发生了!you are creating new SqlParameter object
     the following works for me
    private static void Page_Load(object sender, System.EventArgs e)
    {
        SqlParameter param = new SqlParameter("@Id", SqlDbType.Int);
        param.Value = 1;    RunProc("test",param);
        RunProc("test",param);             
    }
    public static void RunProc(string procName, SqlParameter pram) 
    {
        SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
        con.Open();    SqlCommand cmd = new SqlCommand(procName, con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(pram);
        cmd.ExecuteNonQuery();    con.Close();
        cmd.Parameters.Clear();
    }