Solved

Re-fill dataset with different select statement

Posted on 2009-05-13
2
403 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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