troubleshooting Question

VSTO - fill a ComboBox with a connection string

Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland asked on
Visual Basic.NET
5 Comments1 Solution518 ViewsLast Modified:
Hi

In VB.net I want to populate a ComboBox on a Windows form from a connection string.
The below code works for a DataGridView but not for a ComboBox
Sub FillDGV_Sales()
        Try


            Dim MYDOC_DIR As String = Environ("userprofile") & "\my documents"
            Dim oFullPath As String = MYDOC_DIR & "\MagicBox.accdb"
            '"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=App_Data\GC.accdb;"
            Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & oFullPath & ";"
            Dim sSQL As String
            'sSQL = "SELECT Suppliers.SupplierName, Sum(DLookUp('Amount','Transactions','[Transaction Type] = " & SQLConvert("'Invoice'") & "')) AS Invoiced, Sum(DLookUp('Amount','Transactions',[Transaction Type]' = " & SQLConvert("'Payment'") & "')) AS Paid, [Invoiced]-[Paid] AS Balance " & _
            '"FROM Suppliers INNER JOIN Transactions ON Suppliers.SupplierID = Transactions.SupplierID" & _
            '"GROUP BY Suppliers.SupplierName"
            sSQL = "SELECT Suppliers.SupplierName, [Invoiced]-[Paid] AS Balance, Sum(DLookUp('Amount','Transactions','[Transaction Type] = ''Invoice''')) AS Invoiced, Sum(DLookUp('Amount','Transactions','[Transaction Type] = ''Payment''')) AS Paid " & _
            "FROM Suppliers INNER JOIN Transactions ON Suppliers.SupplierID = Transactions.SupplierID " & _
            "GROUP BY Suppliers.SupplierName"


            '" & SQLConvert(sSchool) & "'"
            Dim connection As New OleDbConnection(connectionString)
            Dim dataadapter As New OleDbDataAdapter(sSQL, connection)
            Dim ds As New DataSet()
            connection.Open()
            dataadapter.Fill(ds, "Suppliers_table")
            connection.Close()
            DataGridView_Supplier.DataSource = ds
            DataGridView_Supplier.DataMember = "Suppliers_table"

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros