[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 168
  • Last Modified:

Searching In VB

I have three three text boxes namely first name, last name and DOB

 and one datagrid in which i am displaying the  table "students"


I want when the user enters any value in any of the three boxes ( either the full first name, or last name or either the first three letters of  first  or last name , or only DOB),  and click on "Search" button:-

The datagrid will only search  on the basis  of above criteria  and will display the values  from the database... in the datagrid...........................................


Please help me in VB only  as i need it urgently
0
rajender123
Asked:
rajender123
  • 2
  • 2
1 Solution
 
Ryan ChongCommented:
in your Search button, try add like:

...
SQL = "Select * from yourTable "
tmp = " WHERE "
If FirstName.Text <> "" then tmp = tmp & " FirstName Like '%" & Replace$(FirstName.Text,"'","''") & "%' And "
If LastName.Text <> "" then tmp = tmp & " LastName Like '%" & Replace$(LastName.Text,"'","''") & "%' And "
If DOB.Text <> "" then tmp = tmp & " DOB = #" & DOB & "# And "     'Change # to ' if necessary, depends on your database using

If tmp = " WHERE " then
    tmp = ""
Else
   tmp = left$(tmp, len(tmp) - 4)
End if
SQL = SQL & tmp

If rs.state = adStateOpen Then rs.Close
rs.Open SQL, conn, adOpenKeyset, adLockOptimistic

Set datagrid1.DataSource = rs
datagrid1.ReBind
datagrid1.Refresh
...
0
 
rajender123Author Commented:
Thanks.. for this...  i want that when the serch results come in datagrid...(since i have  multiple values  of  the same student  with different dates) so the datagrid  will display all the values......................... of  ame student with different visit dates..........

Now  i   want if i  select one row...... all the records will be displayed in the text boxes:- namely


name
first name
last name
visit date
dob
place


Also, the search results  should also be present  at the same time....................

Can u please help  me out in VB.............................................
0
 
Ryan ChongCommented:
>>Now  i   want if i  select one row...... all the records will be displayed in the text boxes:- namely
I think this is the new question from this thread, you can try:

1. Open a New Question with this requirement or
2. Increase this question's points

so that we can help here.

cheers
0
 
rajender123Author Commented:
I have  increased the points  also
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now