VB中单击在 DataGrid1 所显示列表的某一行,如何获得该行第二列的内容? 大哥大姐救急啊!!! 5
源代码如下,应该怎么办?应该再加一些什么东西? 谢谢啊!
Option Explicit
Dim adoCon As New ADODB.Connection
Dim Adors As ADODB.Recordset
Dim sql As String
Private Sub Command1_Click()
DataGrid1.SetFocus
'判断名称是否为空 '连接查询语言
Text1.Text = Trim(Text1.Text) '-------不需要清空,留着下次修改条件再次查询
Text2.Text = Trim(Text2.Text)
Text3.Text = Trim(Text3.Text)
Text4.Text = Trim(Text4.Text)
Text5.Text = Trim(Text5.Text)
Text6.Text = Trim(Text6.Text)
sql = "" '连接查询语言
If Text1 <> "" Then '若Text1不为空则:
If sql <> "" Then sql = sql & " And "
sql = "名称 like '%" & Text1.Text & "%'"
End If
'判断类别是否为空
If Text2 <> "" Then
If sql <> "" Then sql = sql & " And "
sql = "类别 Like '%" & Text2.Text & "%'"
End If
'判断气动布局是否为空
If Len(Trim(Text3)) <> 0 Then
If sql <> "" Then sql = sql & " And "
sql = "气动布局 Like '%" & Text3.Text & "%'"
End If
'判断最大航程是否为空
If Len(Trim(Text4)) <> 0 Then
If sql <> "" Then sql = sql & " And "
sql = "最大航程 >= " & Text4.Text
End If
'判断zaojia1是否为空
If Len(Trim(Text5)) <> 0 Then
If sql <> "" Then sql = sql & " And "
sql = "造价(万元) >= " & Text5.Text
End If
'判断zaojia2是否为空
If Len(Trim(Text6)) <> 0 Then
If sql <> "" Then sql = sql & " And "
sql = "造价(万元) <= " & Text6.Text
End If
If sql <> "" Then sql = " Where " & sql
sql = "Select * From 飞行器" & sql & "" 'SQL查询语言
Adodc1.RecordSource = sql
Adodc1.Refresh
End Sub
Private Sub Command3_Click()
Unload Me
End Sub 展开
Imports System.Data.SqlClient
Imports System.Data.OleDb
Public Class glyh
Dim conn As New SqlConnection("server=.\SQLEXPRESS;database=students;uid=sa;pwd=sa")
Dim da As New SqlDataAdapter()
Dim ds As New DataSet()
Dim str As String
Dim str1 As String
Dim a As Integer
Dim comstr As String
Private Sub glyh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
ds.Reset()
conn.Open()
da = New SqlDataAdapter("select * from users", conn)
da.Fill(ds, "users")
Me.dgv1.DataSource = ds.Tables("users")
yonghuming.DataBindings.Add(New Binding("text", ds, "users.用户名"))
mima.DataBindings.Add(New Binding("text", ds, "users.密码"))
yonghuleixing.DataBindings.Add(New Binding("text", ds, "users.用户类型"))
mimatishiwenti.DataBindings.Add(New Binding("text", ds, "users.问题"))
mimatishidaan.DataBindings.Add(New Binding("text", ds, "users.答案"))
Catch ex As Exception
MessageBox.Show("数据库连接失败" & ex.ToString)
Finally
conn.Close()
End Try
End Sub
Private Sub dgv1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgv1.SelectionChanged
Me.BindingContext(ds, "users").Position = Me.dgv1.CurrentCell.RowIndex
End Sub
Private Sub sousuo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sousuo.Click
For i As Integer = 0 To Me.dgv1.Rows.Count - 1
If Me.dgv1.Rows(i).Cells(0).Value.Equals(Me.ssyhm.Text) Then
Me.dgv1.CurrentCell = Me.dgv1.Rows(i).Cells(0)
Me.BindingContext(ds, "users").Position = Me.dgv1.CurrentRow.Index
End If
Next
End Sub
End Class