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

08-15 11:01