|
-
Jun 11th, 2013, 08:03 AM
#1
Thread Starter
Junior Member
[RESOLVED] Retrieve value from table and How to store in string variable
Hello,
I want to store some data to string array that came from Database table.
The table Data is (only a column):
Alice Mutton
Aniseed Syrup
Boston Crab Meat
Camembert Pierrot
Carnarvon Tigers
...
...
I want to store this retrieved data to String array like (Programetically):
string[] data = {"Alice Mutton", "Aniseed Syrup", "Boston Crab Meat", "Camembert Pierrot", "Carnarvon Tigers"};
How can I fix it?
best regards
ehsan
-
Jun 11th, 2013, 08:09 AM
#2
Re: Retrieve value from table and How to store in string variable
Follow the CodeBank link in my signature and check out my thread on Retrieving & Saving Data. One of the examples uses a data reader to read the result set of a query one record at a time. You can create a List<string> and then read the data the same way and add each value to that list. When you're done, you can just use the List as is or, if you specifically need an array, you can call its ToArray method.
-
Jun 12th, 2013, 02:53 PM
#3
Thread Starter
Junior Member
Re: Retrieve value from table and How to store in string variable
Finally I got it Here is the code
Code:
PfolioDataContext db = new PfolioDataContext();
string conStr = System.Configuration.ConfigurationManager.ConnectionStrings["PortfolioDBConnectionString"].ConnectionString;
SqlDataAdapter adpt = new SqlDataAdapter("select PortID, pName from Portfolio", conStr);
DataTable dt = new DataTable();
adpt.Fill(dt);
int TotalRow = dt.Rows.Count;
string[] res = new string[TotalRow];
for (int i = 0; i < TotalRow; i++)
{
res[i] = dt.Rows[i]["pName"].ToString();
}
This problem is solved
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|