我正在创建一个类,根据数据库中的数据检查checklistbox上的项目。 但是得到错误'名称'ChechState在当前上下文中不存在' 请帮帮我 public void getMinistry(ref System.Windows.Forms.CheckedListBox cr,string strID) { SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings [ConnectionString]); conn.ConnectionString =Data Source = USER-PC; Initial Catalog = PIWCDB;用户ID = sa;密码=迈克; conn.Open(); SqlCommand cmd = new SqlCommand(); string sqlQuery = null; sqlQuery =SELECT Ministryname FROM tblMembershipministry WHERE FormattedMembershipid ='+ strID +'; cmd.Connection = conn; cmd.CommandText = sqlQuery; cmd.CommandType = System.Data.CommandType.Text; System.Data.SqlClient.SqlDataReader dr = null; dr = cmd .ExecuteReader(); while(dr.Read()) { cr.SetItemCheckState( cr.Items.IndexOf(dr [Ministryname]),CheckState.Checked); } cmd.Dispose(); }
am creating a class to check the items on the checklistbox base on the data in the db. but am getting the error 'the name "ChechState" does not exist in the current context' please help me out public void getMinistry(ref System.Windows.Forms.CheckedListBox cr, string strID) { SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); conn.ConnectionString = "Data Source=USER-PC;Initial Catalog=PIWCDB;User ID=sa;Password=mike"; conn.Open(); SqlCommand cmd = new SqlCommand(); string sqlQuery = null; sqlQuery = "SELECT Ministryname FROM tblMembershipministry WHERE FormattedMembershipid ='" + strID + "'"; cmd.Connection = conn; cmd.CommandText = sqlQuery; cmd.CommandType = System.Data.CommandType.Text; System.Data.SqlClient.SqlDataReader dr = null; dr = cmd.ExecuteReader(); while (dr.Read()) { cr.SetItemCheckState(cr.Items.IndexOf(dr["Ministryname"]), CheckState.Checked); } cmd.Dispose(); }
推荐答案我认为你的问题是那个您尚未导入所需的命名空间以使用CheckState。您已在另一个cs文件中定义此方法。尝试导入所需的程序集(我不记得哪个程序集,我正在寻找它,我会尽快发布它,但尝试导入System.Windows.Forms) 再见! Hi, I think your problem is that you have not imported the namespaces you need in order to use CheckState. You've defined this method in another cs file. Try to import the required assembly (I do not remember which assembly, I'm looking for it and I'll post it asap, but try to import System.Windows.Forms) Bye!
更多推荐
在我的班级中使用Checkstate时如何避免出现错误信息
发布评论