クエリで複数の行を返す方法について助けを求めています。たとえば、列の内容全体にアクセスする場合は、すべての行を ListBox に返します。
Imports System.Data.OleDb
Public Class Form1
Dim theConnectionString As New OleDbConnection
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
txtSQL.Clear()
theResults.Items.Clear()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
theConnectionString.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Marc Wilson\Documents\FiddleFuckDB.accdb"
theConnectionString.Open()
Dim theDataSet As New DataSet
Dim theDataTable As New DataTable
theDataSet.Tables.Add(theDataTable)
Dim theDataAdapter As New OleDbDataAdapter
Dim theSQLStatement As String
Dim theDBCommand As New OleDbCommand
theSQLStatement = txtSQL.Text
Try
theDataAdapter = New OleDbDataAdapter("SELECT [City] FROM PI", theConnectionString)
theDataAdapter.Fill(theDataTable)
Dim theRowCount As Integer = theDataTable.Rows.Count
Dim theItemCount As Integer = theDataTable.Columns.Count
MessageBox.Show("Row Count: " & theRowCount & vbNewLine & "Item Count: " & theItemCount, "Your Results...")
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Try
theDBCommand = New OleDbCommand(theSQLStatement, theConnectionString)
theResults.Items.Add(theDataTable.Rows(0).Item(0))
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
theConnectionString.Close()
End Sub
End Class
私が使用しているSQLステートメントはSELECT [City] FROM PI
(3行のデータと4つの異なる列があります)私の間違いはこの部分にあると思います theResults.Items.Add(theDataTable.Rows(0).Item(0))