Solved

Problem Using Stored Procedures

Posted on 2009-04-06
2
188 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 500 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

707 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