Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim connectionString = "Provider=SQLOLEDB.1;Data Source=(local);Persist Security Info=True;User ID=rucio;Password=password;Initial Catalog=TestDb" Dim cn As New OleDbConnection(connectionString) Dim crRow As Integer Dim crValue As String Dim com As OleDbCommand crRow = (DataGridView1.CurrentRow.Index) crValue = DataGridView1.Item(0, crRow).Value.ToString() com = New OleDbCommand("SELECT X座標,Y座標 FROM 管理番号座標 WHERE 管理番号='" & crValue & "'", cn) Dim adapter As New OleDbDataAdapter(com) Dim table As New DataTable adapter.Fill(table) adapter.Dispose() cn.Dispose() Dim x As Integer = table.Rows(0)("X座標") Dim y As Integer = table.Rows(0)("Y座標") MsgBox("X座標は" & x) MsgBox("Y座標は" & y) End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click Dim connectionString = "Provider=SQLOLEDB.1;Data Source=(local);Persist Security Info=True;User ID=rucio;Password=password;Initial Catalog=TestDb" Dim cn As New OleDbConnection(connectionString) Dim crRow As Integer Dim crValue As String Dim com As OleDbCommand crRow = (DataGridView1.CurrentRow.Index) crValue = DataGridView1.Item(0, crRow).Value.ToString() com = New OleDbCommand("SELECT X座標 FROM 管理番号座標 WHERE 管理番号='" & crValue & "'", cn) cn.Open() Dim x As Integer = com.ExecuteScalar cn.Close() com.Dispose() cn.Dispose() MsgBox("X座標は" & x) End Sub