Link to home
Start Free TrialLog in
Avatar of mathieu_cupryk
mathieu_cuprykFlag for Canada

asked on

Value of type 'System.Data.DataTable' cannot be converted to 'System.Data.DataSet'

Can you check this function it is suppose to return a dataset not a datatable. I would appreciate any help.


        Public Function GetCustomerListForDatePeriods(ByVal dbName As String, ByVal dt As DataTable) As DataSet

            ' Read First entry from DataTable   2004 01   2004 01 29  2004 02 25  three entrees
            ' Get the second and third entry of the first row of the datatable
            ' Second Entry will be DT_FROM and third entry will be DT_TO_MONTH
            ' Read Last entry from  DataTable   2005 03   2005 0X 0X  2003 03 03
            ' So we need the first row and last row of the datatable
            ' Third entry of the last row
            Dim dr1 As DataRow
            Dim dr2 As DataRow


            If (dt.Rows.Count > 0) Then

                dr1 = dt.Rows(dt.Rows.Count - 1)

            End If


            If (dt.Rows.Count > 0) Then

                dr2 = dt.Rows(0)  ' Brings back first row

            End If



            Dim retVal As New DataSet("Customers")
            Dim cmd As DbCommand
            Dim tmpds As DataSet
            Dim StoredProcName As String = String.Empty

            Try
                StoredProcName = dbName & ".dbo.usp_GetPrestigeCustomers"

                cmd = dbManager.GetStoredProcCommand(StoredProcName)
                cmd.CommandTimeout = 0


                dbManager.AddInParameter(cmd, "@DT_FROM", DbType.DateTime, IsNull(dr2.Item(1)))           ' Second Entry will be of first row
                dbManager.AddInParameter(cmd, "@DT_TO", DbType.DateTime, IsNull(dr1.Item(2)))             ' Third entry of the last row
                dbManager.AddInParameter(cmd, "@DT_TO_MONTH", DbType.DateTime, IsNull(dr2.Item(2)))       ' Third entry will be of first row


                'Temporarilly put the results in a dataset so we can check for valid data
                tmpds = dbManager.ExecuteDataSet(cmd)

                'We must ensure that only one table was returned in the execution of the query
                If tmpds.Tables.Count.Equals(1) Then

                    'We also need to ensure that there is data
                    If tmpds.Tables(0).Rows.Count > 0 Then
                        retVal = tmpds.Tables(0)
                    Else
                        '  Return retVal
                    End If
                Else
                    ' Return retVal
                End If

            Catch ex As Exception
                Throw ex
            Finally
                'Cleaning up
                If Not tmpds Is Nothing Then
                    tmpds.Dispose()
                End If

                If Not cmd Is Nothing Then
                    cmd.Dispose()
                End If

            End Try

            Return retVal

        End Function
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
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 mathieu_cupryk

ASKER

just did.