在我的班级中使用Checkstate时如何避免出现错误信息

编程入门 行业动态 更新时间:2024-10-23 23:20:58
本文介绍了在我的班级中使用Checkstate时如何避免出现错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在创建一个类,根据数据库中的数据检查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时如何避免出现错误信息

本文发布于:2023-11-03 20:15:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555984.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:出现错误   班级   信息   Checkstate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!