DataTableを取得するには?

240 views
Skip to first unread message

RR Question

unread,
Dec 14, 2014, 8:57:16 PM12/14/14
to rapidrepo...@googlegroups.com
実際にDBからデータを取得する際には、.NETではSqlDataSource等を用いてクエリを実行すると思いますが、その場合DataTableを取得するにはどのようにすればよいですか?

RapidReport

unread,
Dec 14, 2014, 9:04:55 PM12/14/14
to rapidrepo...@googlegroups.com
DataTableを取得するには、SqlDataSourceではなく、DataAdapterというものを利用します。VBでSqlServerからデータを取得する場合のコード例を以下に紹介します。
Dim con As New SqlConnection()
Dim cmd As New SqlCommand()
Dim ds As New DataSet()

con.ConnectionString = "接続文字列"

Using adapter As New SqlDataAdapter()
  cmd.Connection = con
  cmd.CommandText = "SELECT * FROM ..."
  adapter.SelectCommand = cmd
  adapter.Fill(ds)
End Using

Dim dataTable As DataTable = ds.Tables(0)
Reply all
Reply to author
Forward
0 new messages