Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim cn As New SqlClient.SqlConnection 'SQL接続用オブジェクト
Dim cmd As New SqlClient.SqlCommand 'SQL接続コマンド
Dim ds As DataSet 'データセット
Dim tb As DataTable 'データテーブル
Dim ttt As String
'接続文字列を指定
cn.ConnectionString = "Integrated Security=SSPI;" & _
"Persist Security Info=False;" & _
"Initial Catalog=TESTDB;" & _
"Data Source=FUKU;" & _
"Workstation ID=FUKU;"
'接続
Try
cn.Open()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
'コマンド作成
cmd.Connection = cn
'クエリ文字列を指定する
cmd.CommandText = "SELECT * FROM TEST_tbl WHERE NAME = 'BBB'"
adp.SelectCommand = cmd
'データセットクリアー&作成
ds = New DataSet
ds.Clear()
'データセット作成
Try
adp.Fill(ds, "TEST_tbl")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
cn.Close() '接続クローズ
tb = ds.Tables(0)
For i As Integer = 0 To tb.Rows.Count - 1 '行の数だけループ
ttt = tb.Rows(i).Item("ID")
ttt &= Space(1) & tb.Rows(i).Item("NAME")
ListBox1.Items.Add(ttt)
Next i
End Sub
|