Private Sub item2()
        Dim str As String = "Provider=Microsoft.ACE.Oledb.12.0;Data source=C:\Users\user\Desktop\記帳程式\Database1.accdb"
        Dim conn As OleDbConnection = New OleDbConnection(str)
        conn.Open()
        '查詢資料
        Dim str1 As String = "select * from 資料表2 where 時段"
        Dim adp1 As OleDbDataAdapter = New OleDbDataAdapter(str1, conn)
        '將查詢結果放到記憶體set1上的"1a "表格內
        Dim set1 As DataSet = New DataSet
        adp1.Fill(set1, "1a")
        '將記憶體的資料集合存放到視窗畫面上的DataGrid上
        DataGridView2.DataSource = set1.Tables("1a")


      For i = 0 To DataGridView2.RowCount - 1
            ComboBox1.Items.Add(set1.Tables("1a").Rows(i).Item("時段"))
        Next

        '關閉資料庫的連結
        conn.Close()
End Sub

阿倫 發表在 痞客邦 PIXNET 留言(0) 人氣()