Link to home
Start Free TrialLog in
Avatar of jackwebb22002
jackwebb22002Flag for United States of America

asked on

Problem Using Stored Procedures

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

ASKER CERTIFIED SOLUTION
Avatar of jjardine
jjardine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jackwebb22002

ASKER

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.