Solved

Load data into datatable and set as itemsource

Posted on 2013-01-28
2
437 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
[X]
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
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

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