Solved

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

Posted on 2007-04-04
3
1,608 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:mathieu_cupryk
  • 2
3 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
Comment Utility
I believe it's this line:

retVal = tmpds.Tables(0)

change to simply
retVal = tmpds
0
 

Author Comment

by:mathieu_cupryk
Comment Utility
just did.
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
:)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now