Question Database for contacts

Pajamas33

Member
Joined
May 9, 2010
Messages
5
Programming Experience
Beginner
I want to have a database of contacts that has, for example, the email addresses of people. So I know how to make this database, but I want to be able to have the person type a name (of a contact) in a textbox and the program will be able to recognize the name as a contact and be able to send an email to that person with just their name in the textbox.

I know I could use a conditional statement that would say if the textbox has a certain name entered then use a certain email address. THe only problem is what if the person changes the database of contacts? How could I make this work for whatever contacts a person enters into the database?

It would be easy just to have a textbox linked with the database, but I wanted to have it so that if the person entered more than one name in the textbox, then it would send the email to both people.
 
Last edited:
If all you have is the names and the email addresses are in the database then obviously you will have to query the database. You'll need to split the list of names in the TextBox and then query the database for each one to get the corresponding email address(es). If there's exactly one then your job is easy: add that to the list of addresses for the email. You have to decide what to do if there is no match for one of the names and what to do if there are multiple matches.
 
I figured out how to do the search query. But what do you mean when you say split the list of names in textbox? What is an effective way of doing this? The only way I can think of doing this is searching for instances of "; " in the textbox and then returning the character position and then using this to read the name after it. Is there a better way to do this?
 
Use the String.Split method. You tell the character you want to split on (most likely ';') and it will return a String array containing the values in between the delimiters. You can also specify multiple delimiters, e.g. ';' and ','.
 
Back
Top