?
Solved

Problem Using Stored Procedures

Posted on 2009-04-06
2
Medium Priority
?
191 Views
Last Modified: 2013-11-26
I'm having a problem using a stored procedure when trying to get all rows of a table.

I have a property (see code snippet) named "AllRows" which returns a strongly typed DataTable table of all rows in a SQL mdf DB.
When I execute, an Exception is caught and the message says that:
            LastError      "Unable to cast object of type 'System.Data.DataTable' to type 'DestinationDataTable'."

Stored procedure is also attached in code snippet.

Thanks, and Any help on this topic would be most appreciated.
JJW
''' <summary>
    ''' All rows in a data table
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared ReadOnly Property AllRows() As TravelDataSet.DestinationDataTable
        Get
            Try
                Return DirectCast(Utils.GetTable("spAllDestinations", CommandType.StoredProcedure), TravelDataSet.DestinationDataTable)
            Catch ex As Exception
                LastError = ex.Message
                Return Nothing
            End Try
        End Get
    End Property
 
 
    ''' <summary>
    ''' All rows in a data table
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared ReadOnly Property AllRows() As TravelDataSet.DestinationDataTable
        Get
            Try
                Return DirectCast(Utils.GetTable("spAllDestinations", CommandType.StoredProcedure), TravelDataSet.DestinationDataTable)
            Catch ex As Exception
                LastError = ex.Message
                Return Nothing
            End Try
        End Get
    End Property
 
 
 
Stored Procedure:
ALTER PROCEDURE dbo.spAllDestinations
AS
	SET NOCOUNT ON;
	SELECT	DestinationId, 
		Destination,
		Address,
		City, 
		State,
		Zip,
		PhoneNumber,
		DailyCost,
		DepositPctRequired,
		RoomCapacity 
	FROM	[Destination]

Open in new window

0
Comment
Question by:jackwebb22002
[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 14

Accepted Solution

by:
jjardine earned 2000 total points
ID: 24083572
have a look at this:  http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/c085e126-694a-4224-bef8-41b8ae69d7db/    

It is not possible to cast a datatable to a typed datatable object.  The link mentions using a merge to transfer the data into the typed datatable.
0
 

Author Closing Comment

by:jackwebb22002
ID: 31567349
Thanks very much.  I can easily get by with the Getdata method of the dataset's TableAdapter, but needed confirmation that it's not ordinarily possible to do this without something like the merge mentioned in the link.

Now I know I can proceed, with all SP's for other functions, and use the Getdata to retrieve an entire table.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

649 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