Load data into datatable and set as itemsource

Posted on 2013-01-28
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 '' tp type 'system.collections.IEnumerable' and explicit conversion exists.

 private void LoadDataset()

            using (SqlConnection c = new SqlConnection("XXX"))

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

                    DataTableV2.ItemsSource = t;

Open in new window

Many Thanks,
Question by:deanlee17
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

Expert Comment

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

DataTableV2.datasource = t

Accepted Solution

esolve earned 500 total points
ID: 38826562
DataGrid1.DataSource = ds; //where ds = dataset which contains your table
DataGrid1.DataMember = ds.Tables[0].TableName;

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

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

728 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