Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Load data into datatable and set as itemsource

Posted on 2013-01-28
2
Medium Priority
?
450 Views
Last Modified: 2013-01-28
Hi guys,

I am trying to load data into a datatable and set the datatable as the itemsource of a datagrid.

My code below seems until it comes to setting the itemsource of the datagrid to t, the error message is....

Cannot implicitly convert type 'system.data.datatable' tp type 'system.collections.IEnumerable' and explicit conversion exists.

 private void LoadDataset()
        {

            using (SqlConnection c = new SqlConnection("XXX"))
            {
                c.Open();

                using (SqlDataAdapter a = new SqlDataAdapter("select * from SQ_SysproHis_Step3", c))
                {
                    DataTable t = new DataTable();
                    a.Fill(t);

                    DataTableV2.ItemsSource = t;
                }
            }
            
        }

Open in new window


Many Thanks,
Dean
0
Comment
Question by:deanlee17
2 Comments
 
LVL 9

Expert Comment

by:sognoct
ID: 38826552
if DataTableV2 is your datagrid , you should use:

DataTableV2.datasource = t
0
 
LVL 6

Accepted Solution

by:
esolve earned 2000 total points
ID: 38826562
//ASP.NET
DataGrid1.DataSource = ds; //where ds = dataset which contains your table
DataGrid1.DataMember = ds.Tables[0].TableName;
DataGrid1.DataBind();

//Silverlight
datagrid.ItemsSource = dataset.Tables[0].DefaultView;

http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.itemssource(v=vs.95).aspx

So in your case if you're using silverlight I suppose you can bind to the
t.DefaultView
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question