473,387 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Search text box for first name AND last name

294 256MB
I have a text box where users will enter a first and last name, and then search by those parameters. I can find plenty of examples and have done search functions where first name and last name are separate text boxes, however I am not sure how to go about this.

I understand it would be some kind of concatenation, yet I'm not sure how to go about it (Parameters, etc.). I am also curious on how to handle whether or not the user enters "FirstName LastName" or "LastName FirstName" in the text box. I suppose it would be the same logic just reversed.

Anyone ever done something like this who could provide insight? Here is what I have so far...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Searchbtn_Click(sender As System.Object, e As System.EventArgs) Handles Searchbtn.Click
  2.         Dim SQLConnection As New SqlClient.SqlConnection("Data Source=SQLTEST_HR,4000\SQLEXPRESS;Integrated Security=True")
  3.         SQLConnection.Open()
  4.         Dim SqlCommand As New SqlClient.SqlCommand("Select * FROM PARTICIPANT", SQLConnection)
  5.  
  6.  
  7.         Dim SQLReader As SqlClient.SqlDataReader
  8.         SQLReader = SqlCommand.ExecuteReader
  9.         'Need Parameter
  10.  
  11.         If SQLReader.Read Then
  12.  
  13.         End If
Jan 10 '14 #1

✓ answered by Rabbit

I would split the input by a space delimiter and look for the individual values in the first and last name fields.

12 4042
Rabbit
12,516 Expert Mod 8TB
Why not separate the inputs?
Jan 10 '14 #2
mcupito
294 256MB
Rabbit, thanks for replying. Honestly, I wanted to just have knowledge of how this could be performed and have a better understanding of searching for items in a database (somewhat like Google's search). In no way is this method mandatory, however it was just a preference to be able to do it.
Jan 10 '14 #3
Rabbit
12,516 Expert Mod 8TB
I would split the input by a space delimiter and look for the individual values in the first and last name fields.
Jan 10 '14 #4
mcupito
294 256MB
Hmm. So I would create two variables, say First and Last.
Assign them to the two values that would be delimited.
and in the search button handler I would use those variables as the parameters?
Jan 10 '14 #5
Rabbit
12,516 Expert Mod 8TB
Pretty much. It would be something like:
Expand|Select|Wrap|Line Numbers
  1. string1 = string before space
  2. string2 = string after space
  3.  
  4. sql = where (first name = string1 and last name = string2) or (first name = string2 and last name = string1)
Jan 10 '14 #6
mcupito
294 256MB
Do you know how to declare the text in the textbox to a variable to delimit? I am getting an error "'Variable of type 1-dimensional array of String' cannot be converted to string.

Expand|Select|Wrap|Line Numbers
  1. Dim Search = Searchtxt.Text
  2.         Dim searchArray As String = Split(Searchtxt.Text)
  3.  
  4.         Dim NonEmpty As Integer = -1
  5.         For i As Integer = 0 To searchArray.Length - 1
  6.             If searchArray(i) <> "" Then
  7.                 NonEmpty += 1
  8.                 searchArray(NonEmpty) = searchArray(i)
  9.             End If
  10.         Next
  11.         ReDim Preserve searchArray(NonEmpty)
Jan 10 '14 #7
Rabbit
12,516 Expert Mod 8TB
I don't understand what you are trying to do. You are basically setting the array equal to itself, I don't understand the purpose of trying to do that.
Jan 10 '14 #8
mcupito
294 256MB
I've given up for now, haha. Thanks for your assistance, Rabbit.
Jan 10 '14 #9
Rabbit
12,516 Expert Mod 8TB
Don't give up just yet. You don't need any of the code from lines 4 through 11. None of that was in my pseudo code. You just need to go straight to the filter now.
Jan 11 '14 #10
mcupito
294 256MB
I managed to get it to work. Here's my code for the OnClick Event for a button:

Expand|Select|Wrap|Line Numbers
  1.         Dim Search As String() = DelimitTxt.Text.Split(" ")
  2.         Dim first As String = Search(0)
  3.         Dim last As String = Search(1)
  4.  
  5.         eFirsttxt.Text = first
  6.         eLasttxt.Text = last
Jan 17 '14 #11
Rabbit
12,516 Expert Mod 8TB
Glad you got it working.
Jan 17 '14 #12
mcupito
294 256MB
Thanks for the encouragement, Rabbit.
Jan 20 '14 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Prasad Karunakaran | last post by:
I am using the C# DirectoryEntry class to retrieve the Properties of an user object in the Active Directory. I need to get the First Name and Last Name as properties. I know it is not supported...
3
by: GoCMS | last post by:
Hi, all: This might be a newbie question. How to get a user's name and email from his/her NT login? I know that in .net, we can user System.DirectoryServices to do so, but not sure if there's a...
3
by: Edmund Wong | last post by:
I have one client fiield that stores First and last name. I would like to separate the names into a lastname field and firstname field. Can anyone tell me how to do this? thanks
1
by: ambr | last post by:
i made a class with personType and addressType .now ineed to search for a person by last name in c++and print the names of all all the people between two last names.somebody tell me the best way to...
4
by: John | last post by:
Good Day all I have a single field that has both the first and last names in it. In some records we even have a middle initial. I was thinking of using the Left (Fullname,XX) function to get the...
0
by: Trevor2007 | last post by:
I am trying to retrieve the windows account holders first and last name for the that is currently logged in, I would like to do it with WMI since object.get doesn't work very well with VBA. (Need to...
2
dlite922
by: dlite922 | last post by:
I'm reading a CSV file and the firstname and last name are together separated by a space. (There could be middle name or middle initial as well, but is being ignored) Since i'll be doing this...
5
by: jmurphy | last post by:
What do i add to this script to validate the entry? Thanks in advance for the help. <form name="continue" method="POST" action="shipping1.asp" onsubmit="return validate_form ();"> <input...
3
by: Mo Ewing | last post by:
I have a field in my database with people's names. Each field has only one first name but may have more than one last name. The first name is always the first word in the field. I would like to...
1
by: hexyz hexagonal | last post by:
This is the code I have for the person.java file // Person.java // Creates and manipulates a person with a first name, last name and age public class Person { private String...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.