Click here to Skip to main content
13,199,852 members (69,760 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
Posted 13-Dec-12 4:45am
OriginalGriff 13-Dec-12 10:46am
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
You need to tell us more about what kind of data you are getting from your database, and how you need it converted to a string array. Otherwise we have to guess, and that really isn't a good strategy!
Use the "Improve question" widget to edit your question and provide better information.
ryanb31 13-Dec-12 11:14am
Where are you stuck? There are a million ways to do this and it will depend on the classes you have.
Master Black 13-Dec-12 12:04pm
Yes I agree with Griff and ryanb. One of the simplest way is you call your database connection in a method and declare your string array in that method and access your database result into that string array and return that array.

But Its not advisable to use string[] returning from a function.

You can return an object of a class that holds your data returning from the database.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


Try this

DataTable DT=new DataTable();
string[] arr;
string StrArray = string.Join(",", (from DataRow row in DT.Rows select (string)row["DataTableColumnName"]).ToArray());
arr = StrArray.Split(',');
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171020.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100