0
public static void DropDownList_Bind(DropDownList list_name,string DtaTxtField,string DataValueField,String Procedure)
   {
       OpenConnection();
       com = new SqlCommand(Procedure, con); 
       com.CommandType = CommandType.StoredProcedure;
       SqlDataReader dtr = com.ExecuteReader();
       list_name.DataSource = dtr;
       list_name.DataTextField = DtaTxtField;
       list_name.DataValueField = DataValueField;
       list_name.DataBind();
       dtr.Close();
       CloseConnection();
   }
public static void OpenConnection()
    {
        if(con.State==ConnectionState.Closed)
            con.Open();

    }
    public static void CloseConnection()
    {
        if (con.State == ConnectionState.Open)
            con.Close();
    }

这是我用于绑定 DropDownList 的业务逻辑代码,它给出了一个 execption已经有一个与此命令关联的打开的 DataReader 必须先关闭。关于。SqlDataReader dtr = com.ExecuteReader();请给一些建议。提前感谢

4

1 回答 1

1

您需要在连接字符串中设置“MultipleActiveResultSets=True”。

我在以下链接上写了一篇博文。

http://www.dotnetjalps.com/2013/06/Entity-Framework-There-is-already-an-open-DataReader-associated-with-this-Command.html

问候,

于 2013-07-11T13:16:04.063 回答