在我的班级中使用Checkstate时如何避免出现错误信息 [英] How Do I Avoid Getting An Error Message When Using Checkstate In My Class

查看:57
本文介绍了在我的班级中使用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时如何避免出现错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆