We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,089 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

vb6 search code in datagrid

hi, im new in vb6
how to search in datagrid where every keyword you type wil display the record
found in database? here's my code in saving
pls ned help here....this is our thesis
God Bless>thanks.

Sub search()
'search if student is registered then
With ado
    .ConnectionString = connectdb
    .RecordSource = "Select * from info where Barcode = '" & Text2 & "'"
    .Refresh

    If .Recordset.RecordCount > 0 Then
    Text3 = ado.Recordset!Barcode
    Text4 = ado.Recordset!fname
    Text5 = ado.Recordset!lname
    Text6 = Date

'student attendance check
    Call add

 End If




End With


End Sub

 Public Sub add()
'save to attendance record
With adoadd.Recordset
.AddNew
!Barcode = Text3
!First_Name = Text4
!Last_Name = Text5
!Date = Text6
.Update
MsgBox "save", vbInformation, "message"

Text2 = ""
Text3 = ""
Text4 = ""
Text5 = ""
Text6 = ""
End With
DataGrid1.Refresh
End Sub
3
Contributors
6
Replies
4 Days
Discussion Span
5 Months Ago
Last Updated
12
Views
Question
Answered
vonnoy
Light Poster
31 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

how to search in datagrid where every keyword you type wil display the record
found in database?

You want to search in datagrid or search record in database?

Jx_Man
Senior Poster
3,529 posts since Nov 2007
Reputation Points: 1,482
Solved Threads: 516
Skill Endorsements: 64

yes, thats it,like if i type on the txtbox automatically display on the datagrid
but dont know how to code it.
can u help me?

vonnoy
Light Poster
31 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Ok. So when you type on textbox then there are data display on datagrid.
Use textbox change event to make searching every you type a word on textbox.
This is an example of searching using datagrid. Modified as you needed.

Private Sub Text1_Change()
 Set rs = New ADODB.Recordset
        rs.CursorType = adOpenDynamic
        rs.LockType = adLockOptimistic
        rs.Open "SELECT * FROM Login where fname  like " & "'%" & Text1.Text & "%'", Conn, , , adCmdText

    Set DataGrid1.DataSource = rs
    DataGrid1.Columns(0).Width = 2000
    DataGrid1.Columns(1).Width = 2000

    DataGrid1.AllowAddNew = False
    DataGrid1.AllowArrows = True
    DataGrid1.AllowDelete = False
    DataGrid1.AllowUpdate = False
End Sub
Jx_Man
Senior Poster
3,529 posts since Nov 2007
Reputation Points: 1,482
Solved Threads: 516
Skill Endorsements: 64

thank you so much, it works.

vonnoy
Light Poster
31 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You're welcome.
Don't forget to mark this thread as Solved.
Happy Coding.

Jx_Man
Senior Poster
3,529 posts since Nov 2007
Reputation Points: 1,482
Solved Threads: 516
Skill Endorsements: 64

Hi,
This may be useful to find data from Grid.
Please find attached project.
It will be able to find and replace the text from MSFlexGrid's Cells

Attachments Find_And_Replace_Grid.zip (9.07KB)
deepakbshitole
Newbie Poster
7 posts since May 2012
Reputation Points: 0
Solved Threads: 1
Skill Endorsements: 0
Question Answered as of 5 Months Ago by Jx_Man and deepakbshitole

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0722 seconds using 2.67MB