返回首页


message system.invalidoperationexception: the connection was not closed current state is open. at system.data.providerbase.dbconnectioninternal.openconnection(dbconnection outerconnection,dbconnectionfactory connectionfactory) at system.data.sqlclient.sqlconnection.open() at pay_roll.show_in_datagridview()

回答

评论会员:CGN007 时间:2012/02/06
添加此代码
{C}
前打开连接
评论会员:潘迪亚阿尼尔 时间:2012/02/06
我的理解,你要填写一格,得到错误

为错误的描述,你正试图打开一个已经打开SQL连接在你的方法 - GT。pay_roll.show_in_datagridview()

所以加之前开放的连接
支票
SqlConnection myConnection = new ...(...);

if (myConnection.State == ConnectionState.Closed)

{

    myConnection.Open();

}

另外,您可以使用与非托管资源的SqlConnection一样,这将强制使用后的资源propper闭幕。工作时使用关键字

标记为答复是否满意... {S0的}激励......