Solved

Re-fill dataset with different select statement

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

815 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

11 Experts available now in Live!

Get 1:1 Help Now