搞了我两天的search function做到了,分享一下。。。

这个是vb.net coding

我放那一个部分的code 大家看一下应该要怎么写。。

这个是我找到的sample code…
Private Sub BtnRetrieve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRetrieve.Click
mode = False
CboRetrieve.Visible = True
TxtIDno.Visible = False
CboRetrieve.Enabled = True
TxtIDno.Enabled = False
Call combo()
Call clearCombo()
End Sub

这个是我已经写好的code…里面有add,delete,save…只差search…
Private Sub ContactsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContactsBindingNavigatorSaveItem.Click
Me.Validate()
Me.ContactsBindingSource.EndEdit()
Me.ContactsTableAdapter.Update(Me.TongCustomersDataSet.Contacts)

End Sub

怎么写search的 function???
需要随便打一个 car 就可以找出全部关于car的公司。。。

Search function. . . let the user key in the customer code then your software should display the customer record that match the customer code.

A good search function should not only limit the user search by the customer code, but others field also like customer name, customer address, customer phone number or etc. . .

A good search function should not only limit the user search by the exact search value, which only display 1 record, but also any others records that contain/within/between the search value.

http://code.google.com/search/#q=vb.net%20search

里面有资料吗?

i need something like this… quick search function

my boss request something like this … whatever he type…
display the record that related…

he type K then display whatever about K… he type car… display the record have car… he type a date then display what tat day have been sold … something like this… if only search by a code its easy … but thanks any way for ur advice ya…
quicksearch.JPG
quicksearch1.JPG
quicksearch2.JPG

thanks ya… a lot coding there… still searching for it

Private Sub txtSearchCustomer_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSearchCustomer.TextChanged

Dim itemFound As Integer = Me.CusBindingSource.Find(“这里要改什么?”, txtSearchCustomer.Text)
Me.CusBindingSource.Position = itemFound
Me.CusBindingSource.
End Sub

那边我空了,就出现这个error msg :DataMember property ‘’ cannot be found on the DataSource.

这个。。。。。。。。。。。。。。。又有问题=。=
帮帮忙看什么事情

DataMember 还有 DataSource 要在哪里找???

小宇,你的问题。。。
和尚已经看了。。。
你要搞清楚,你现在的database是需要分类的。如果是随便key in一个字母进去,而一次过读完所需要资料,那么就很简单。。
可是,你的老板的要求不是,是需要已经要分类好的资料而已。这叫做DataGrid,是需要分类的。
因此,你先搞清楚你的database。
如果单单只是叫一个顾客的全部资料,而不需要分类的,那么就简单很多。

给以一个例子:

在FORM的LOAD事件中加入:

Data1.DatabaseName = 数据库名称
Data1.RecordSource = 表名
Data1.Refresh

在按的CLICK把database加入中

Dim Irow, Icol As Integer
Dim Irowcount, Icolcount As Integer
Dim Fieldlen() "
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject(“Excel.Application”)
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)

With Data1.Recordset.MoveLast

If .RecordCount < 1 Then
MsgBox (“Error Not record!”)
Exit Sub
End If

Irowcount = .RecordCount "
Icolcount = .Fields.Count "

ReDim Fieldlen(Icolcount).MoveFirst

For Irow = 1 To Irowcount + 1
For Icol = 1 To Icolcount
Select Case Irow
Case 1 "
xlSheet.Cells(Irow, Icol).Value = .Fields(Icol - 1).Name
Case 2 "FIELDLEN()

   If IsNull(.Fields(Icol - 1)) = True Then
    Fieldlen(Icol) = LenB(.Fields(Icol - 1).Name)
 
   Else
    Fieldlen(Icol) = LenB(.Fields(Icol - 1))
   End If

   xlSheet.Columns(Icol).ColumnWidth = Fieldlen(Icol)
   
   xlSheet.Cells(Irow, Icol).Value = .Fields(Icol - 1)
    
  Case Else
   Fieldlen1 = LenB(.Fields(Icol - 1))

   If Fieldlen(Icol) < Fieldlen1 Then
    xlSheet.Columns(Icol).ColumnWidth = Fieldlen1
    
    Fieldlen(Icol) = Fieldlen1
    
   Else
    xlSheet.Columns(Icol).ColumnWidth = Fieldlen(Icol)
   End If

   xlSheet.Cells(Irow, Icol).Value = .Fields(Icol - 1)
  End Select
 Next
 If Irow <> 1 Then
  If Not .EOF Then .MoveNext
 End If
Next

With xlSheet
.Range(.Cells(1, 1), .Cells(1, Icol - 1)).Font.Name = “Bold”
"
.Range(.Cells(1, 1), .Cells(1, Icol - 1)).Font.Bold = True

.Range(.Cells(1, 1), .Cells(Irow, Icol - 1)).Borders.LineStyle = xlContinuous

End With
xlApp.Visible = True
xlBook.Save
Set xlApp = Nothing
End With

你仔细看,在click 加入database中,有很多种分类data,例如:Irowrowcount Fieldle xlApp xlBoo xlSheexlAppxlBook xlSheelS。那就是要你要重点了。。。

谢谢和尚的例子哦。。。大概抓到concept了

Private Property CompanyName() As String
Get
Return _companyNAMEValue
End Get
Set(ByVal value As String)
_companyNAMEValue = value
End Set
End Property

我用了这个方法。。。可是又有问题
error message:

Warning 1 property ‘CompanyName’ shadows an overloadable member declared in the base class ‘Control’. If you want to overload the base method, this method must be declared ‘Overloads’. C:\Documents and Settings\Acer\My Documents\Visual Studio 2005\Projects\Tong Turbo Customer Management System ver1\Tong Turbo Customer Management System ver1\Form2.vb 4 22 XXXXCustomer Management System ver1


Public Sub LoadData()
If Me.CompanyName.Trim().Length > 0 Then
Me.ContactsTableAdapter.FillbyCompanyName(Me.TongCustomersDataSet.Contacts, Me.CompanyName)

End If
End Sub

Error 2 ‘FillbyCompanyName’ is not a member of ‘WindowsApplication1.TongCustomersDataSetTableAdapters.ContactsTableAdapter’. C:\Documents and Settings\Acer\My Documents\Visual Studio 2005\Projects\Tong Turbo Customer Management System ver1\Tong Turbo Customer Management System ver1\Form2.vb 35 13 Tong Turbo Customer Management System ver1

我做到了。。。 分享一下

弄一个connection function, 在 form load那边 call它回去

Private Sub ConnectDB()
Dim conn As OleDbConnection
Dim adp As OleDbDataAdapter
Dim ds As DataSet
Dim sql As String
Dim sConnString As String

sConnString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=[Database path];Jet OLEDB:Database Password=;”
conn = New OleDbConnection(sConnString)
sql = “SELECT * FROM [Database’s Table Name]”
adp = New OleDbDataAdapter(sql, conn)
ds = New DataSet
adp.Fill(ds)

DataGridView1.DataSource = ds.Tables(0)

adp.Dispose()
conn.Close()
conn.Dispose()

End Sub

然后就是search function, 在search button 那边call他回去

Private Sub Search()
Dim conn As OleDbConnection
Dim adp As OleDbDataAdapter
Dim ds As DataSet
Dim sql As String
Dim sConnString As String

sConnString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=[Database path];Jet OLEDB:Database Password=;”
conn = New OleDbConnection(sConnString)
sql = “SELECT * FROM [Database table] WHERE [Data field] LIKE '%” + SearchTextBox.Text + “%’”
adp = New OleDbDataAdapter(sql, conn)
ds = New DataSet
adp.Fill(ds)

DataGridView1.DataSource = Nothing
DataGridView1.DataSource = ds.Tables(0)

adp.Dispose()
conn.Close()
conn.Dispose()
End Sub

这个是把search 回来的result放回去 DisplayForm里面。。是clickdatagrid里面的row就出来的。。。。

Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick

If IsDBNull(DataGridView1.SelectedRows.Item(0).Cells(1).Value) = False Then

/" 当然 sJobCard 是之前已经declare好了的。。。是public value

sJobCard = DataGridView1.SelectedRows.Item(0).Cells(1).Value
End If
Me.Hide()

End Sub

然后在DisplayForm里面

Private Sub FindButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindButton.Click
Dim frm As New SearchForm()
frm.ShowDialog()
JobCardTxt.Text = frm.sJobCard
End Sub