Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have created a dictionary.I need to fetch query from my database using LINQ and add it to the datatable..then I need to loop through the datatable get the results and store it in the dictionary..I need to know how to add the data to the dattable..below is my part of the code
C#
public static void fetchdata()
       {
           string USER_ID="AH01"
         
            northwinddatacontext nc= new northwinddatacontext();//datacontext where I have added my table called username

            Dictionary<string,> types = new Dictionary<string,>();
            DataTable dt = new DataTable();

            var result =      from x in nc.usernames
                        	where (x.userId == USER_ID) 
                       		 select x
                       				
             dt=Common.LINQToDataTable(result);

            foreach (DataRow row in dt.Rows)
            {
                nwind nw = new nwind ();
                nw.userID = row.Field<string>("userID").ToString();
                types .Add(nw.userID, nw);
               

            }
          
       }</string>
Posted
Updated 25-Apr-13 21:13pm
v3
Comments
Bojjaiah 26-Apr-13 3:20am    
edit and add pre tag!.....
Orcun Iyigun 26-Apr-13 3:36am    
Why do you need a datatable, what is the usage of it? Why don't you add the data directly to dictionary from your returned result set?
sindhuan 26-Apr-13 4:47am    
I can loop through the datatable and display the record which I wanted.
Orcun Iyigun 26-Apr-13 5:00am    
your result set is consists of strings? So why don't you put them into a generic list and go from there? And here are 2 links which helps you to convert list to datatable: Link 1[^] and Convert a Generic List to a Datatable[^]. But still I really cant understand why you cant use your "var result" to accomplish this?
sindhuan 26-Apr-13 5:39am    
It consists of strings..but I'm supposed to do with datatable..It will be really helpful if u could help me on that

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