将数据库中的数据加载到字符串数组 [英] Loading data from database into string array

查看:58
本文介绍了将数据库中的数据加载到字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮帮我,我想要一个返回类型必须为string []的方法,并且在该方法中我想从sql server数据库加载列值,请帮我一个示例代码段

解决方案

您好,



试试这个



DataTable DT =新的DataTable ();

string [] arr;

if(DT.Rows.Count> 0)

{

string StrArray = string.Join(,,(来自DT.Rows中的DataRow行)select(string)row [DataTableColumnName])。ToArray());

arr = StrArray.Split ('','');

}


雅,有很多方法。你必须尝试google,它会更好地探索你。



但你问,所以试试 - >



  String  SourceData;  //  来存储来自列的数据 
string [] strArr = new string [SourceData];
char [] splitchar = {' ' };
strArr = str.Split(splitchar);





在strArr中,你会找到你想要的o / p。 / BLOCKQUOTE>

Hi, please help me i want a method whose return type must be string[] and in that method i want to load columns values from sql server database,please help me with a sample snippet

解决方案

Hi,

Try this

DataTable DT=new DataTable();
string[] arr;
if(DT.Rows.Count>0)
{
string StrArray = string.Join(",", (from DataRow row in DT.Rows select (string)row["DataTableColumnName"]).ToArray());
arr = StrArray.Split('','');
}


Ya,there are many ways.1st u have to try google, it will explore u much better.

But u ask,so try->

String SourceData;  //to store data from column 
string[] strArr = new string[SourceData];
char[] splitchar = {' '};
strArr = str.Split(splitchar);



Here in strArr u will found o/p as u want.


这篇关于将数据库中的数据加载到字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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