Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Load data into datatable and set as itemsource

Posted on 2013-01-28
2
433 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 500 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

789 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