S_John

I have done it!

Right, first off, I was stupid. That is one problem when you're over worked, and over - used your brain...

anyways. I cannot comprehend why I never created a new datatable ( for our filtered results ) and never made use of a paramater. Again, I apologise - you could have been finished with this, If my brain wasn't needing a FORMAT and RELOAD .

Have a look here :

Code:
Imports System.Data.OleDb

Public Class Form1
    'Database connection variables
    Private da As OleDbDataAdapter
    Private conn As OleDbConnection
    Private bsource As BindingSource = New BindingSource()
    Private ds As DataSet = Nothing
    Private udtSQLCmd As String

    'Database connection for the BoM Database
    Private sBoMConnectionString As String = "Data Source=OMDC-SCADADEV1;Initial Catalog=BoM;Persist Security Info=True;User ID=****;Password=****"
    Private sCMMSConnectionString As String = "Data Source=OMDC-SCADADEV1;Initial Catalog=CMMS;Persist Security Info=True;User ID=****;Password=****"


    Private Sub FilterMe()

        conn = New OleDbConnection(sBoMConnectionString) 

        udtSQLCmd = "SELECT * FROM Motor WHERE HorsePower = @HorsePower" '+ cboMotorVoltage.SelectedValue + "'" 'ADDED PARAMATER INTO QUERY AND REMOVED LIKE

        Dim oSelCmd As OleDbCommand = New OleDbCommand
        oSelCmd.Parameters.Add("@HorsePower", OleDbType.VarChar, 20).Value = cboMotorVoltage.SelectedValue.ToString 'CREATED PARAMETER HERE
        oSelCmd.CommandType = CommandType.Text
        oSelCmd.Connection = conn
        oSelCmd.CommandText = udtSQLCmd
        Dim dt As New DataTable 'DATATABLE TO STORE OUR FILTERED RESULTS
        conn.Open()

        dt.Load(oSelCmd.ExecuteReader)
        cboMotorHP.DisplayMember = "HorsePower"
        cboMotorHP.DataSource = dt 'SET DATA SOURCE TO NEW DATATABLE

    End Sub


    Private Sub cboMotorVoltage_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboMotorVoltage.SelectedIndexChanged

        FilterMe()

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'THIS ASSUMES THAT YOU HAVE ADDED THE DATA CONTROLS AT DESIGN TIME
        'TODO: This line of code loads data into the 'VoltagesDataSet1.Motor' table. You can move, or remove it, as needed.
        Me.MotorTableAdapter.Fill(Me.VoltagesDataSet1.Motor)
        'TODO: This line of code loads data into the 'VoltagesDataSet.Motor' table. You can move, or remove it, as needed.


    End Sub

End Class
You just need to set the ValueMember Property of the cboMotorVoltage combobox to Voltage

Once again, I apologise. It happens

Let me know how it goes!!!

Hannes

Quote Originally Posted by dglienna View Post
Just say IF BLANK then X, if Not BLANK, do Y. Then check for X and Y and fill either /or.

Should be able to do it in 2-3 IF statements. Create a BOOLEAN or two.
Ever heared of Parameters ?