Click here to Skip to main content
13,086,120 members (82,923 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am using Sql Database for backend and i am working on some project based on Windows application. In that application i am using Datatable in order to retrive data from Sqldatabase and trying to add that data in to string List, but unfortunetly its not happening. Please help
here is the Code....

List<string> viru = new List<string>().ToList();
        public void GetName()
            //Reading Data from VirusDataBase
            SqlCommand commandObject = new SqlCommand("Select Virus_Name from Virus", connection);
            SqlDataAdapter sda = new SqlDataAdapter(commandObject);
            DataTable dtVirusList = new DataTable();

            if (dtVirusList.Rows.Count > 0)
Posted 5-Dec-12 18:33pm
Updated 5-Dec-12 18:44pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

use arraylist instead.
arraylist al =new arraylist();
foreach(datarow str in dtviruslist.rows)
// otherwise add to your list ie. viru
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try this I hope it will help you

How do you convert a DataTable into a generic list?[^]

Keep smiling :):):) happy coding:)
Nikhil@123 6-Dec-12 0:51am
Hi Thanks for REplying,
i have already gone through with that link, that case is completly different than my case. i have retrieved data from sqldatabase and have added to DataTable and now i wants to add that entire data to string list at one time without using ForEach or ForLoop. I hope you understood .
Keep Smiling :) :) :) happy coding :) .

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 |
Web03 | 2.8.170813.1 | Last Updated 7 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