1

I have a stored-procedure like this :

ALTER PROCEDURE [dbo].[SelectUserInfo] 

AS
BEGIN
select * from User_Info
END 

and I am using LINQ to call this procedure and want store the data in a datatable or dataset here what I am doing :

DataClassesDataContext dc = new DataClassesDataContext();
DataTable dt = null;
dt = (DataTable)dc.SelectUserInfo();

but its not working its giving error.

the error is this :

Unable to cast object of type 'SingleResult`1[SelectUserInfoResult]' to type 'System.Data.DataTable'.

Please help me to do this ...

6
  • i have included the error now please take a look Commented Aug 24, 2013 at 12:08
  • I don't think you can directly cast the results to the DataTable. The results is of type SelectUserInfoResults which you must have defined it in some function import. Commented Aug 24, 2013 at 12:23
  • can you explain or show how ... Commented Aug 24, 2013 at 12:26
  • 1
    One of the points of LINQ is to avoid using datasets. The idea is that instead you have a collection of entities. Commented Aug 24, 2013 at 12:36
  • the thing is i have a method inside a class which i want to return datatable or dataset so i can call that method in my application and have a datatable Commented Aug 24, 2013 at 12:38

1 Answer 1

1

Make sure you really do need a DataTable/DataSet.

The DBML file creates a return class for your Stored Procedure, in your case there is a class SelectUserInfoResults that got created when you added the stored procedure SelectUserInfo to your dbml file.

So if you are not being forced to use DataTables/DataSet you could simply create a List<SelectUserInfoResults> as your return type.

DataTables/DataSets and Linq To Entities classes are of very different nature, I would recommend to avoid mixing them whenever possible.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.