1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| Private m_ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\Northwind 2007.accdb;"
Public Function selectdistinct(ByVal Table As String) As DataView
Dim daTable As New OleDbDataAdapter
Dim dtTable As New DataTable
Dim sqlstring As String = "SELECT DISTINCT [Nom expédition] FROM " & Table
Using connection As New OleDbConnection(m_ConnectionString)
Dim command As New OleDbCommand(sqlstring, connection)
' Open the connection and execute the insert command.
Try
connection.Open()
command.ExecuteNonQuery()
daTable.SelectCommand = command
daTable.Fill(dtTable)
Return New DataView(dtTable)
Catch ex As Exception
Console.WriteLine(ex.Message)
MessageBox.Show(ex.Message)
Return Nothing
End Try
End Using
End Function
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.CbxFour.DataSource = selectdistinct("Commandes")
Me.CbxFour.DisplayMember = "Nom expédition"
End Sub |