ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文

  メンテナンス 前画面に戻る

対象スレッド 件名: 【VB.NET】COM経由の ADODB で EXCEL を 参照
名前: lightbox
処理選択
パスワード

件名 【VB.NET】COM経由の ADODB で EXCEL を 参照
名前 lightbox
コメント
http://lightbox.cocolog-nifty.com/photos/app/ref_studio.png

http://lightbox.cocolog-nifty.com/photos/app/ref_adodb_2.png

↓商品分類マスタ.xls
http://lightbox.on.coocan.jp/download/syobun_xls.lzh

[[Excel 参照]]
@DIV
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

	' exe が存在するディレクトリ
	Dim ProgPath As String = Application.StartupPath
	Dim ExcelPath As String = ProgPath & "\商品分類マスタ.xls"

	Dim ConnectionString As String = _
	   "Provider=Microsoft.Jet.OLEDB.4.0;" & _
	   "Data Source=" & ExcelPath & ";" & _
	   "Extended Properties=""Excel 8.0;IMEX=1;"""

	Dim Cn As ADODB.Connection = New Connection()
	Try
		Cn.Open(ConnectionString)
	Catch ex As Exception
		MessageBox.Show(ex.Message)
		Exit Sub
	End Try

	Dim Rs As ADODB.Recordset = New Recordset()
	Dim Query As String = "select * from [商品分類マスタ]"
	Try
		Rs.Open(Query, Cn)
	Catch ex As Exception
		MessageBox.Show(ex.Message)
		Cn.Close()
		Exit Sub
	End Try

	Dim Buffer As String = ""
	Do While Not Rs.EOF
		For i As Integer = 0 To Rs.Fields.Count - 1
			If i <> 0 Then
				Buffer = Buffer & ","
			End If
			Buffer = Buffer & Rs.Fields(i).Value
		Next
		Buffer = Buffer & ControlChars.CrLf

		Rs.MoveNext()
	Loop

	Rs.Close()
	Cn.Close()

	MessageBox.Show(Buffer)

End Sub
@END