Read Access97 + Create + Listbox












Imports system.data.oledb
Imports System.Text
Public Class Form2
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim strdb As String = "c:\dthai97.mdb"
        Dim strconn As String = "provider=microsoft.jet.oledb.4.0;data source=" & strdb
        Dim strsql As String = "select fid,fname,fsalary from tbthai"
        Dim cn As New System.Data.OleDb.OleDbConnection(strconn)
        Dim cm As New OleDbCommand(strsql, cn)
        Dim dr As OleDbDataReader
        cn.Open()
        dr = cm.ExecuteReader()
        Dim font As New Font(New FontFamily("lilyupc"), 20, 0, GraphicsUnit.Pixel)
        Dim lb As New ListBox
        Controls.Add(lb)
        lb.Font = font ' MsgBox(lb.Font.Name.ToString())' "microsoft sans serif"
        While dr.Read()
            'Dim xbyte() As Byte = System.Text.Encoding.Unicode.GetBytes(dr.Item("fname"))
            'Dim xbuffer() As Byte = Encoding.Convert(Encoding.Default, Encoding.GetEncoding("windows-874"), xbyte)
            'Dim o As String = Encoding.GetEncoding("unicode").GetString(xbuffer)
            'lb.Items.Add(Encoding.ASCII.GetString(xbuffer) & o)
            lb.Items.Add(dr.Item("fname"))
            ListBox1.Items.Add(dr.Item(1))
        End While
        lb.Show()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strdb As String = "c:\dthai97.mdb"
        Dim strconn As String = "provider=microsoft.jet.oledb.4.0;data source=" & strdb
        Dim strsql As String = "select fid,fname,fsalary from tbthai"
        Dim cn As New OleDbConnection(strconn)
        Dim cm As New OleDbCommand(strsql, cn)
        Dim dr As OleDbDataReader
        cn.Open()
        dr = cm.ExecuteReader()
        Dim x As String
        While dr.Read()
            x = x & dr.Item(0) & dr.Item(1) & dr.Item(2) & Chr(10)
        End While
        MsgBox(x)
    End Sub
End Class

http://goo.gl/72BPC