Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

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
0
SweetingA
Asked:
SweetingA
1 Solution
 
Luis PérezSoftware Architect in .NetCommented:
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.
0
 
AndyAinscowCommented:
>>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.
0
 
SweetingAAuthor Commented:
Yes you are right, i was just a fool - it was so simple in the end, they completed instantaneously
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now