Solved

Re-fill dataset with different select statement

Posted on 2009-05-13
2
398 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

12 Experts available now in Live!

Get 1:1 Help Now