PC Review


Reply
Thread Tools Rate Thread

CopyToDataTable() how?

 
 
Russ Sherlock
Guest
Posts: n/a
 
      27th Apr 2009
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'.



 
Reply With Quote
 
 
 
 
Frank Uray
Guest
Posts: n/a
 
      28th Apr 2009
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


"Russ Sherlock" wrote:

> 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'.
>
>
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with CopytoDataTable() after a query in linq Ivan Microsoft VB .NET 2 16th Feb 2009 08:54 AM
PRB: DataTable.GetErrors.CopyToDataTable() Doesn't Copy the Column Errors Charles Law Microsoft Dot NET 0 6th Sep 2008 06:24 PM
Casting DataTable to typed when using DataTableExtensions.CopyToDataTable Andrew Jocelyn Microsoft C# .NET 3 19th Mar 2008 02:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:36 AM.