2009年4月9日木曜日

【VB】DdataReaderにデータを取得させる

dataReader=command.ExecuteReader()で取得


Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

'接続情報
Dim cn As New System.Data.OleDb.OleDbConnection
cn.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;" _
& "data source="Order.mdb"

'選択コマンド
Dim cmd As New OleDbCommand
cmd.Connection = cn
cmd.CommandText = "select * from goods"

'接続
cn.Open()
MessageBox.Show("接続しました")

Dim dreader As OleDbDataReader
dreader = cmd.ExecuteReader

'DataReaderの内容を確認
Dim i As Integer
Do While dreader.Read()
For i = 0 To dreader.FieldCount - 1
Console.Write(dreader(i) & ControlChars.Tab)
Next
Console.WriteLine()
Loop

'切断
cn.Close()
End Sub

0 件のコメント:

コメントを投稿