日期:2014-05-18  浏览次数:20729 次

求大侠帮助......ADO.NET的
button1.Enabled = (myConnection.State = ConnectionState.Closed);
button2.Enabled = (myConnection.State = ConnectionState.Open);

这是测试数据库连接状态里面的两句代码,是VB的代码。
我想用c#来实现,就直接在VS里面用。
但是编译不成功。
提示是:无法对属性或索引器“System.Data.Common.DbConnection.State”赋值 -- 它是只读
  无法将类型“System.Data.ConnectionState”隐式转换为“bool“


------解决方案--------------------
button1.Enabled = (myConnection.State == ConnectionState.Closed);
button2.Enabled = (myConnection.State == ConnectionState.Open);
------解决方案--------------------
myConnection.State = ConnectionState.Closed
这句话是赋值啊,当然会出错
myConnection.State == ConnectionState.Closed