在gridView数据中搜索vb.net [英] search in gridView data vb.net

查看:73
本文介绍了在gridView数据中搜索vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



创建一个数据库,例如学生数据库.

GridView列,例如

名称ID标记

拉维101 98
mohan 102 97
........
.... ... ...

我想创建一个文本框和searchButton的另一种花

在文本框中,我将名称键入ravi并单击SearchButton,以显示ravi的所有详细信息.



hi create one database for example student database.

GridView column such as

name id mark

ravi 101 98
mohan 102 97
.... .. ..
.... ... ...

i want i create anther form one textbox and searchButton

the textbox i type the name as ravi and click the SearchButton display all the details of ravi.

推荐答案

将aaa用作整数
私有Sub sea_Click(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理sea.Click
试试
aaa = TextBox1.Text
con.Open()
Dim da As New OleDbDataAdapter(从其中code ="&(TextBox1.Text),con)的产品中选择*
昏暗的dt作为新的数据表
da.Fill(dt)
如果dt.Rows.Count< = 0则
MsgBox(此数字不存在",MsgBoxStyle.DefaultButton1,不存在")
其他
DataGridView1.DataSource = dt
code.Text = dt.Rows(cur)(1).ToString
pro.Text = dt.Rows(cur)(2).ToString
com.Text = dt.Rows(cur)(3).ToString
buy.Text = dt.Rows(cur)(4).ToString
sell.Text = dt.Rows(cur)(5).ToString
date1.Text = dt.Rows(cur)(6).ToString
如果结束
异常捕获
MsgBox(输入正确的代码")
终于
con.Close()
结束尝试
结束子
Dim i As Integer
私有子DataGridView1_CellClick(ByVal发送者作为对象,ByVal e作为System.Windows.Forms.DataGridViewCellEventArgs)处理DataGridView1.CellClick

试试
con.Open()
昏暗的dt作为新的数据表
将Dim ds用作新数据集
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter
da =新的OleDbDataAdapter(从产品中选择*",同上)
da.Fill(dt)

我= DataGridView1.CurrentRow.Index
code.Text = DataGridView1.Item(1,i).Value
pro.Text = DataGridView1.Item(2,i).Value
com.Text = DataGridView1.Item(3,i).Value
buy.Text = DataGridView1.Item(4,i).Value
sell.Text = DataGridView1.Item(5,i).Value
date1.Text = DataGridView1.Item(6,i).Value

异常捕获
MsgBox(ex.Message)
结束尝试
con.Close()

结束Sub
Dim aaa as Integer
Private Sub sea_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sea.Click
Try
aaa = TextBox1.Text
con.Open()
Dim da As New OleDbDataAdapter("select * from products where code=" & (TextBox1.Text), con)
Dim dt As New DataTable
da.Fill(dt)
If dt.Rows.Count <= 0 Then
MsgBox("This Number Does Not Exist", MsgBoxStyle.DefaultButton1, "Not Exist")
Else
DataGridView1.DataSource = dt
code.Text = dt.Rows(cur)(1).ToString
pro.Text = dt.Rows(cur)(2).ToString
com.Text = dt.Rows(cur)(3).ToString
buy.Text = dt.Rows(cur)(4).ToString
sell.Text = dt.Rows(cur)(5).ToString
date1.Text = dt.Rows(cur)(6).ToString
End If
Catch ex As Exception
MsgBox("Enter a correct code")
Finally
con.Close()
End Try
End Sub
Dim i As Integer
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick

Try
con.Open()
Dim dt As New DataTable
Dim ds As New DataSet
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter
da = New OleDbDataAdapter("select * from Products", con)
da.Fill(dt)

i = DataGridView1.CurrentRow.Index
code.Text = DataGridView1.Item(1, i).Value
pro.Text = DataGridView1.Item(2, i).Value
com.Text = DataGridView1.Item(3, i).Value
buy.Text = DataGridView1.Item(4, i).Value
sell.Text = DataGridView1.Item(5, i).Value
date1.Text = DataGridView1.Item(6, i).Value

Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Close()

End Sub


hi,

试试这个...



try this...

dim qry = From therow as DataGridViewRow In DataGridView1.Rows,
          thecell as DataGridViewCell In therow.Cells 
          Where thecell.value.ToString = TextBox1.Text Select thecell

Dim cells()=qry.ToArray


现在使用cells()...

如有任何疑问,请回复我...


now use the cells()...

any doubt reply me...


这篇关于在gridView数据中搜索vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆