如何分配datareader值字符串数组。 [英] how to assign datareader value string array.
问题描述
在这里,我从数据库中获取10条记录,并使用sqldatareader读取这10条记录,如下所示
sqlDataReader reader = cmd.ExecuteReader();
//在读者中,我有来自数据库的记录。
while(reader.Read() )
{
string [] arpp_pro = new string [] {reader [records] .ToString()};
}
一切正常..它不是在阵列中分配位置。
在第一时间循环时,[0]有第一个记录
在循环时第二次,[1]有第二次记录。但这里[0]记录不存在。
i需要。
[0] = firstrecord。
[1] =第二条记录。
[3] =第三条记录。
它assingn correctyl。但我只能看到一条记录。
如何解决这个问题。我怎样才能获得10条记录。
hi here i am getting 10 records from database and i used sqldatareader to read those 10 records as follows
sqlDataReader reader = cmd.ExecuteReader();
// in reader, i have records which comes from database.
while(reader.Read())
{
string [] arpp_pro= new string[] {reader["records"].ToString()};
}
everything works fine.. it is not assinging in array position.
while looping at fist time, [0] is having first record
while loopting at second time, [1] is having second record. but here [0] record is not there.
i need.
[0] = firstrecord.
[1] = second record.
[3] = third record.
it assingn correctyl. but i can see one record only.
how to solve this problem. how can i get 10 records.
推荐答案
希望它会有所帮助
使用通用命名空间
使用System.Collections.Generic;
List< string> arpp_pro = new List< string>();
hope it will helps
use Generic namespace
using System.Collections.Generic;
List <string> arpp_pro = new List<string>();
while(reader.Read())
{
arpp_pro.Add(dr[0].Tostring());
}
这篇关于如何分配datareader值字符串数组。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!