您好我有一个查询,它填充了一个正常工作的datagridview。填充数据网格后,它具有以下列
用户名 用户名 UserDepot
我有一个按钮,当按下该按钮时,我想根据UserID列中的信息运行另一个查询,并选择任何行。我编写此查询时遇到困难,因为我不知道为了调用此信息我需要写什么命令
datagrid被称为dg_usersearch,所以我期望使用像dg_usersearch.selectedvalue这样的东西,但是selectedvalue不是datagridview的成员,有人知道我应该使用什么命令吗?
填充数据网格的查询如下
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'creates a list of all incidents as per the search parameters
Dim dt As New DataTable
Dim query As String = "select [userid],[username],[userdepot] from [tbluser]"
Using connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\MyDATASOURCE")
Using command As New OleDbCommand(query, connection)
Using adapter As New OleDbDataAdapter(command)
connection.Open()
adapter.Fill(dt)
connection.Close()
End Using
End Using
End Using
'checks to make sure query has results
If dt.Rows.Count > 0 Then
dgusersearch.DataSource = dt
'if no results display the following message
ElseIf dt.Rows.Count = 0 Then
MsgBox(Prompt:="No results for search request, please try again")
End If
答案 0 :(得分:0)
@Plutronix上面回答,
myDGV.SelectedRows(0).Cells(0).Value.ToString()