Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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....
 
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 5-Dec-12 19:33pm
Edited 5-Dec-12 19:44pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

use arraylist instead.
arraylist al =new arraylist();
 
foreach(datarow str in dtviruslist.rows)
{
   al.add(str["column_name"].tostring());
// otherwise add to your list ie. viru
}
  Permalink  
Rate this: bad
good
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 Smile | :) Smile | :) Smile | :) happy codingSmile | :)
  Permalink  
v2
Comments
Nikhil@123 at 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
0 DamithSL 245
1 Sergey Alexandrovich Kryukov 217
2 OriginalGriff 200
3 Peter Leow 160
4 Afzaal Ahmad Zeeshan 85
0 OriginalGriff 7,380
1 DamithSL 5,359
2 Sergey Alexandrovich Kryukov 4,944
3 Maciej Los 4,906
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2014
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