从数据表中获取每一行的数据并以字符串形式存储 [英] Get the data from every row from datatable and store in string

查看:90
本文介绍了从数据表中获取每一行的数据并以字符串形式存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个数据表充满了来自sql server的数据,所以我可以将所有数据行存储到特定的字符串值ex。数据表有24行,我想将所有行存储在字符串值上,如:string value1 = row1,value2 = row2,value3 = row3 ... value24 = row24,如果有人知道怎么做,我需要一个想法告诉我,谢谢:)

Hi everyone,I have a datatable that is filled up with data from sql server, so can I store all the data rows to the specific string values ex. the datatable has 24 rows, and I want to store all rows on a string values like : string value1 = row1, value2=row2, value3=row3 ... value24=row24, I need an idea please if anyone know how to do it tell me, thanks :)

推荐答案

DataTable dt = new DataT able();



dt = GetDataTableFromSQL();



string str1 = string.empty;

list< string> strLst = new List< string>();

foreach(dt.Rows中的DataRow dr)

{

str1 + = convert.tostring( dr [ColumnName1])+ convert.tostring(dr [ColumnName2])+ ..等等



strLst.add(str1);

}



现在你需要在字符串列表上移动循环并逐个检查字符串中的行。



foreach(strlst中的字符串项目)

{

// item -----

}





谢谢

Prince Sharma
DataTable dt=new DataTable();

dt=GetDataTableFromSQL();

string str1=string.empty;
list<string> strLst=new List<string>();
foreach(DataRow dr in dt.Rows)
{
str1+=convert.tostring(dr["ColumnName1"])+convert.tostring(dr["ColumnName2"])+..so on

strLst.add(str1);
}

Now you need to move loop on string list and check rows in string one by one.

foreach(string item in strlst)
{
//item -----
}


Thanks
Prince Sharma


你可以这样做。



//数据库表中的foreach行

{

//数据库表中的foreach列

{

// Concat并构建一个字符串。使用StringBuilder

}

//将字符串添加到数据表中。

}
You can do something like this.

//foreach row in databasetable
{
//foreach column in databasetable
{
//Concat and build a string.Use StringBuilder
}
//Add the string to your datatable.
}


这篇关于从数据表中获取每一行的数据并以字符串形式存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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