首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

求大侠帮助.ADO.NET的解决方案

2012-04-07 
求大侠帮助......ADO.NET的button1.Enabled (myConnection.State ConnectionState.Closed)button2.En

求大侠帮助......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

热点排行