Running multiple SQL queries at the same time from vb

Posted on 2014-08-04
Last Modified: 2014-08-05
Hello Experts....

This may be a very simple one for those who know but not for me!
I want to populate 4 different charts at the same time from 4 different SQL tables.
The code below i am using for one chart.
Do i simply refernce 4 different adaptors anf datasets or is there a more elegant way?

Thanks in advance

    Private Sub cboPeriodSelector_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboPeriodSelector.SelectedIndexChanged

        If cboPeriodSelector.SelectedIndex = 0 Then
            datStart.Visible = False
            datEnd.Visible = False
            labDateFilter.Visible = False
            labTo.Visible = False
            SQL.RunQuery("SELECT OEE As OEE, Hour As Hour FROM qry_OEE_Hourly")
            If SQL.recordcount = 0 Then
                MsgBox("No records available for this selection", vbExclamation + vbOKOnly, "Message")
                Exit Sub
            End If
            SQL.SQLDA.Fill(SQL.SQLDataSet, "qry_OEE_Hourly")
            ChartOEE.DataSource = SQL.SQLDataSet.Tables("qry_OEE_Hourly")
            Dim Series1 As Series = ChartOEE.Series(0)
            Series1.Name = "Hourly OEE"
            ChartOEE.Series(Series1.Name).XValueMember = "Hour"
            ChartOEE.Series(Series1.Name).YValueMembers = "OEE"
            ChartOEE.Series(0).CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 15"
            ChartOEE.ChartAreas(0).AxisX.Title = "Hour"
            ChartOEE.ChartAreas(0).AxisY.Title = "% OEE"
            ChartOEE.ChartAreas(0).AxisX.Minimum = -1
            ChartOEE.ChartAreas(0).AxisX.Maximum = 24
            ChartOEE.ChartAreas(0).AxisY.Minimum = 0
            ChartOEE.ChartAreas(0).AxisY.Maximum = 120
            ChartOEE.ChartAreas(0).AxisX.Interval = 1
            ChartOEE.ChartAreas(0).AxisY.Interval = 20
            ChartOEE.ChartAreas(0).AxisX.TitleFont = New Font("Arial", 10, FontStyle.Bold)
            ChartOEE.ChartAreas(0).AxisY.TitleFont = New Font("Arial", 10, FontStyle.Bold)
            ChartOEE.ChartAreas(0).AxisX.LabelStyle.Font = New Font("Arial", 6)
            ChartOEE.ChartAreas(0).AxisY.LabelStyle.Font = New Font("Arial", 6)
            ChartOEE.ChartAreas(0).AxisX.MajorGrid.LineDashStyle = DataVisualization.Charting.ChartDashStyle.Dash
            ChartOEE.ChartAreas(0).AxisY.MajorGrid.LineDashStyle = DataVisualization.Charting.ChartDashStyle.Dash
            ChartOEE.ChartAreas(0).AxisX.LabelStyle.Angle = 0
            ChartOEE.Series(0).XValueType = ChartValueType.Int32
            Exit Sub
Question by:SweetingA
    LVL 25

    Expert Comment

    by:Luis Pérez
    If you really want to do it "at the same time", you'll need the help of threading. You can use the core classes from System.Threading as well as the BackgroundWorker control/component, which is easier to use.

    Hope that helps.
    LVL 43

    Accepted Solution

    >>Do i simply refernce 4 different adaptors anf datasets or is there a more elegant way?

    It all depends on what you mean by at the same time.  Assuming all the queries will complete rapidly then it may well be good enough.  However if one query takes 60 seconds and the other three take 1 second in total then even using threading wont be of much help.

    Author Closing Comment

    Yes you are right, i was just a fool - it was so simple in the end, they completed instantaneously

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    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 (…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    761 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

    10 Experts available now in Live!

    Get 1:1 Help Now