Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
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....

C#
List<string> viru = new List<string>().ToList();
        public void GetName()
        {
           
            //Reading Data from VirusDataBase

            connection.Open();
            SqlCommand commandObject = new SqlCommand("Select Virus_Name from Virus", connection);
            SqlDataAdapter sda = new SqlDataAdapter(commandObject);
            DataTable dtVirusList = new DataTable();


            sda.Fill(dtVirusList);
            connection.Close();
            if (dtVirusList.Rows.Count > 0)
            {
                viru..Add(dtVirusList.ToString());
            }
             
        }
Posted
Updated 5-Dec-12 18:44pm
v2

use arraylist instead.
C#
arraylist al =new arraylist();
 
foreach(datarow str in dtviruslist.rows)
{
   al.add(str["column_name"].tostring());
// otherwise add to your list ie. viru
}
 
Share this answer
 
Try this I hope it will help you

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

Keep smiling :):):) happy coding:)
 
Share this answer
 
v2
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900