创建数据搜索 [英] create search of data
本文介绍了创建数据搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我使用了插入,删除和更新从网上获得的数据的代码,但是问题是,当我单击搜索时如何处理代码按钮.我想对数据进行搜索.希望有人能帮助我.这是我正在使用的代码:
Hi all,
I have used this code of insert,delete and update of data that i get from the net but the problem is that how can I do with code when I click on the search button. I wanted to do on the search of the data. Hope that anyone could help me. Here is the code that I am using:
Public Class EditingCust
Dim cmd As OleDbCommand
Dim myAdapter As New OleDbDataAdapter
Dim comBuilder As OleDbCommandBuilder
Dim ds As DataSet
Dim mytable As DataTable
Dim myrow As Data.DataRow
Dim rownumber As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=E:\MajorProjectFile\ProjectSample\database\User.mdb")
myAdapter.SelectCommand = New OleDbCommand("SELECT * FROM customer", con)
comBuilder = New OleDbCommandBuilder(myAdapter)
con.Open()
rownumber = 0
ShowData()
End Sub
'add the columns that need to display the data
Private Sub ShowData()
ds = New DataSet()
myAdapter.Fill(ds, "customer")
mytable = ds.Tables("customer")
myrow = mytable.Rows.Item(rownumber)
TextBox1.Text = myrow.Item("CustName").ToString
TextBox2.Text = myrow.Item("Address").ToString
TextBox3.Text = myrow.Item("Positions").ToString
TextBox4.Text = myrow.Item("CompanyName").ToString
TextBox5.Text = myrow.Item("Email").ToString
TextBox6.Text = myrow.Item("Telephone").ToString
ComboBox1.Text = myrow.Item("Industry").ToString
End Sub
'click on updated button'
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myrow.Item("CustName") = TextBox1.Text.Trim
myrow.Item("Address") = TextBox2.Text.Trim
myrow.Item("Positions") = TextBox3.Text.Trim
myrow.Item("CompanyName") = TextBox4.Text.Trim
myrow.Item("Email") = TextBox5.Text.Trim
myrow.Item("Telephone") = TextBox6.Text.Trim
myrow.Item("Industry") = ComboBox1.SelectedItem.Trim
mytable.GetChanges()
comBuilder.GetUpdateCommand()
myAdapter.Update(ds, "customer")
MsgBox("Record Has been updated")
End Sub
'click on delete button'
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
mytable.Rows.Item(rownumber).Delete()
If MsgBox("Do you really want to delete the data?", MsgBoxStyle.YesNo, "Deleting Data") = MsgBoxResult.Yes Then
comBuilder.GetUpdateCommand()
myAdapter.Update(ds, "customer")
NextButton.PerformClick()
End If
End Sub
'last button'
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
rownumber = mytable.Rows.Count - 1
ShowData()
NextButton.Enabled = False
PreviousButton.Enabled = True
End Sub
'first button'
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
rownumber = 0
ShowData()
PreviousButton.Enabled = False
NextButton.Enabled = True
End Sub
Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextButton.Click
PreviousButton.Enabled = True
rownumber = rownumber + 1
If rownumber > mytable.Rows.Count - 1 Then
rownumber = mytable.Rows.Count - 1
NextButton.Enabled = False
End If
ShowData()
End Sub
Private Sub PreviousButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PreviousButton.Click
NextButton.Enabled = True
rownumber = rownumber - 1
If rownumber < 0 Then
rownumber = 0
PreviousButton.Enabled = False
End If
ShowData()
End Sub
'click on insert button'
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
mytable.Rows.Add()
rownumber = mytable.Rows.Count - 1
myrow = mytable.Rows.Item(rownumber)
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
ComboBox1.Text = ""
End Sub
'click on saves button'
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
myrow.Item("CustName") = TextBox1.Text.Trim
myrow.Item("Address") = TextBox2.Text.Trim
myrow.Item("Positions") = TextBox3.Text.Trim
myrow.Item("CompanyName") = TextBox4.Text.Trim
myrow.Item("Email") = TextBox5.Text.Trim
myrow.Item("Telephone") = TextBox6.Text.Trim
myrow.Item("Industry") = ComboBox1.SelectedItem.Trim
mytable.GetChanges()
comBuilder.GetInsertCommand()
myAdapter.Update(ds, "customer")
MsgBox("Record has been saved")
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
ComboBox1.SelectedItem = Nothing
End Sub
End Class
感谢
注意事项
LiL_Is
thanks
Regards
LiL_Is
推荐答案
.在数据搜索上做.
I wanted to do on the search of the data.
请您更具体吗?我不明白你的想法.你打算怎么办?
Would you please be more specific? I can't get your idea. What are you going to do?
这篇关于创建数据搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文