CopyToDataTable() how?

R

Russ Sherlock

How do I get the results of the _stored procedure_ into a DataTable?
My code fails as shown...

ItemsOnPremisesReport crystalRep = new CrystalItemsOnPremisesReport();
using (GalleryEntities ge = new GalleryEntities())
{
DataTable myTable = (from item in
ge.stockHeldForCust(3).AsEnumerable<Rsp__ItemsOnPremisesReport>()
select item).CopyToDataTable();

crystalRep.SetDataSource(myTable);
crystalReportViewer1.ReportSource = crystalRep;
}

Error 1 The type 'Discovery.GalleryManager.Rsp__ItemsOnPremisesReport'
cannot be used as type parameter 'T' in the generic type or method
'System.Data.DataTableExtensions.CopyToDataTable<T>(System.Collections.Generic.IEnumerable<T>)'.
There is no implicit reference conversion from
'Discovery.GalleryManager.Rsp__ItemsOnPremisesReport' to
'System.Data.DataRow'.
 
F

Frank Uray

Hi Russ

You can use a DataAdapter to fill data into a DataSet.

System.Data.SqlClient.SqlDataAdapter local_DataAdapter = new
System.Data.SqlClient.SqlDataAdapter("someStoredProcedure",
SQLNATIVEConnection);

System.Data.DataSet local_DataSet = new System.Data.DataSet();
local_DataAdapter.Fill(local_DataSet, "DataSetTableName");

After this you can access the table like
local_DataSet.Tables["DataSetTableName"].

Best regards
Frank Uray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top