Solved

Re-fill dataset with different select statement

Posted on 2009-05-13
2
399 Views
Last Modified: 2012-05-06
I have a procedure that fills an FPSpread/Grid.
In this procedure I need to check and see if there are any records in the first dataset and if not I need to refill the dataset with a different select string.
What would be the best way to do this?
Thanks
Function FillSpread() As DataTable

        Dim ds As New DataSet
 

        If DatabaseToUse() = BizObjs.DBType.Access Then
 

            Dim str As String = String.Empty
 

            If mbTaskCars Then

                str = SelectTaskCars()

            ElseIf mbTaskDetailsLU Then

                str = SelectTaskDetailsLU()
 

            End If
 

            Dim dc As New OleDb.OleDbConnection(ConnectionString)

            Dim da As New OleDb.OleDbDataAdapter(str, dc)
 

            Try
 

                da.Fill(ds)

                If ds.Tables(0).Rows.Count = 0 Then
 

                    ds.Clear()

                    
 

                End If

                dc.Close()
 
 

            Catch ex As Exception

                MessageBox.Show(ex.Message)

                dc.Close()
 

            End Try

        End If
 

        Return GenerateDataTable(ds)
 

    End Function

Open in new window

0
Comment
Question by:Sheritlw
2 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 24381849
try something like this
 Function FillSpread() As DataTable

        Dim ds As New DataSet
 

        If DatabaseToUse() = BizObjs.DBType.Access Then
 

            Dim str As String = String.Empty
 

            If mbTaskCars Then

                str = SelectTaskCars()

            ElseIf mbTaskDetailsLU Then

                str = SelectTaskDetailsLU()
 

            End If
 

            Dim dc As New OleDb.OleDbConnection(ConnectionString)

            Dim da As New OleDb.OleDbDataAdapter(str, dc)
 

            Try
 

                da.Fill(ds)

                If ds.Tables(0).Rows.Count = 0 Then
 

                    ds.Clear()

                    str = " New Select stattemet"

                    Dim daNew As New OleDb.OleDbDataAdapter(str, dc)

                    daNew.Fill(ds)

                End If

                dc.Close()
 
 

            Catch ex As Exception

                MessageBox.Show(ex.Message)

                dc.Close()
 

            End Try

        End If
 

        Return GenerateDataTable(ds)
 

    End Function

Open in new window

0
 

Author Comment

by:Sheritlw
ID: 24382228
Thank you. That is what I finally figured out.  
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

932 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

14 Experts available now in Live!

Get 1:1 Help Now