Sql server 2005 在c.net中检索复选框列表值
我想从我的SQLServer2005数据库中检索checkboxlist值,其中我有一个表,表中有一列car,其中包含n个值,如BMW、Jaguar、Royal 现在,我想为checkboxlist中的特定复选框检索它们;我试过:Sql server 2005 在c.net中检索复选框列表值,sql-server-2005,ado.net,Sql Server 2005,Ado.net,我想从我的SQLServer2005数据库中检索checkboxlist值,其中我有一个表,表中有一列car,其中包含n个值,如BMW、Jaguar、Royal 现在,我想为checkboxlist中的特定复选框检索它们;我试过: for (int x = 0; x < checkedListBox1.Items.Count; x++) { if (checkedListBox1.CheckedItems[x].ToString()) { checkedListBox1.Te
for (int x = 0; x < checkedListBox1.Items.Count; x++) {
if (checkedListBox1.CheckedItems[x].ToString()) {
checkedListBox1.Text = sdr.GetString(16).Split(",");
}
}
但它不起作用。我发现以下错误:
“string.Splitparams”的最佳重载方法匹配
char[]”具有一些无效参数
这是SQL查询:
select
RegisterNo, RegistrationDate, Stimulation, PationName,
DateOfBirth, ContactNo, Occupation, Age, Sex, Chief_Complain,
Investigation_Result, PastHistoryAny, Physical_Examination,
Ref_By_Doctor, Medications, Prognosis, Electro_Therapy,
Neuro_Rehabilitation, Ortho_Rehabilitation,
Cardio_Pulmonery_Rehabilitation, Sports_Rehabilitation
from
Physio_cureTable
where
RegisterNo = @RegisterNo
and Syncoperation <> 'D
好的,现在我们有了一条有用的错误消息,不仅它不起作用,我们还可以提供帮助
错误信息似乎非常清楚:
与“string.Splitparams char[]”匹配的最佳重载方法具有一些无效参数
因此,请检查您对.Split的调用—正如您从错误消息中看到的,它需要一个或多个字符作为分隔符。但您并没有提供一个或多个字符-您传递的是一个字符串,而不是一个字符
checkedListBox1.Text = sdr.GetString(16).Split(",");
相应地,将调用更改为实际传入a,作为C中用单引号表示的字符:
然后我相信它应该会起作用
更新:第二个主要问题是.Split返回一个字符串数组,而不仅仅是一个字符串。但是您试图将该字符串数组分配给一个.Text属性,该属性只是一个字符串。那么你想用你得到的10根弦做什么呢?您需要找到一种方法将它们分配给可以容纳多个字符串的对象
如果我正确解释了代码,您很可能希望从数据库表中加载逗号分隔的条目,然后填充CheckListBox
然后你需要像这样的东西:
// clear the list of items
checkedListBox1.Items.Clear();
// parse the loaded comma-separated string into array of individual strings
string[] stringsFromDatabase = sdr.GetString(16).Split(",");
// load those strings into .Items for checklistbox
foreach(string str in stringsFromDatabase)
{
checkedListBox1.Items.Add(str);
}
@Aties:您确定提到的表架构与此sql查询相关吗?没有汽车栏,我怀疑这张表是否包含汽车;顺便说一句,您在ADO.NET中通过reader.GetString检索的列是Neuro_康复,而不是car.ya先生,这是真的,但我给您举一个例子;marc_s sir仍然出错错误5无法隐式转换类型“string[]'到'string'E:\Winform n console\physicure\physicure\physicure\Form1.cs 488 48 physicure显示错误6无法将类型'string'隐式转换为'bool'E:\Winform n console\physicure\physicure\physicure\Form1.cs 497 25 checkedListBox4.CheckedItems[x].托斯特林code@Aties:更新了我的回答,我相信你想要的-你的问题在这方面不是很清楚…非常非常感谢marc_的工作非常感谢n新年快乐亲爱的:
// clear the list of items
checkedListBox1.Items.Clear();
// parse the loaded comma-separated string into array of individual strings
string[] stringsFromDatabase = sdr.GetString(16).Split(",");
// load those strings into .Items for checklistbox
foreach(string str in stringsFromDatabase)
{
checkedListBox1.Items.Add(str);
}