如何将读取器值分配给字符串串通 [英] How to assign reader value to string colloection
本文介绍了如何将读取器值分配给字符串串通的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
如何将读取器值分配给字符串集合
Hi
How to assign reader value to string collection
StringCollection dodetails = new StringCollection();
dodetails = reader.ToString();
我收到以下错误
无法将类型字符串"隐式转换为"System.Collections.Specialized.StringCollection"
请检查
谢谢!
I am getting the below error
Cannot implicitly convert type ''string'' to ''System.Collections.Specialized.StringCollection''
Please check
Thanks
推荐答案
Datareader是一个基于流"的数据对象,该数据只能顺序访问.因此,无法直接将数据读取器分配给字符串集合.
以下是完成您希望的方式之一-
Datareader is a "stream-based" data object and the data can be access only sequentially. So, there is no way to directly assign the data reader to a string collection.
Below is one of the ways to accomplish what you wish -
if (reader.HasRows)
{
while (reader.Read())
{
dodetails.Add(reader.GetString(column_number))
}
}
HTH!
-Dinesh
HTH!
- Dinesh
StringCollection dodetails = new StringCollection();
//Checking whether reader contains any value oe not.
if (reader.HasRows)
{
int i=0;
while (reader.Read())
{
dodetails.Add(reader.GetValue(i));
//Storing all Datarader value into collection
}
}
这篇关于如何将读取器值分配给字符串串通的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文