Link to home
Start Free TrialLog in
Avatar of SweetingA
SweetingA

asked on

Running multiple SQL queries at the same time from vb

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

        SQL.SQLDataSet.Clear()
        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")
                ChartOEE.Series(0).Points.Clear()
                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
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

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.
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SweetingA
SweetingA

ASKER

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