?
Solved

Re-fill dataset with different select statement

Posted on 2009-05-13
2
Medium Priority
?
406 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 2000 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 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