mathieu_cupryk
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 GetCustomerListForDatePeri ods(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_GetPrestigeCusto mers"
cmd = dbManager.GetStoredProcCom mand(Store dProcName)
cmd.CommandTimeout = 0
dbManager.AddInParameter(c md, "@DT_FROM", DbType.DateTime, IsNull(dr2.Item(1))) ' Second Entry will be of first row
dbManager.AddInParameter(c md, "@DT_TO", DbType.DateTime, IsNull(dr1.Item(2))) ' Third entry of the last row
dbManager.AddInParameter(c md, "@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(c md)
'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
Public Function GetCustomerListForDatePeri
' 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_GetPrestigeCusto
cmd = dbManager.GetStoredProcCom
cmd.CommandTimeout = 0
dbManager.AddInParameter(c
dbManager.AddInParameter(c
dbManager.AddInParameter(c
'Temporarilly put the results in a dataset so we can check for valid data
tmpds = dbManager.ExecuteDataSet(c
'We must ensure that only one table was returned in the execution of the query
If tmpds.Tables.Count.Equals(
'We also need to ensure that there is data
If tmpds.Tables(0).Rows.Count
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:)
ASKER