Solved

Load data into datatable and set as itemsource

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now