![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 154
Rep Power: 3
![]() |
mysql database search
so I am writing a C#program that determines whether a given name exists in the MySql database
after determining the database and all that... first, I execute "select * from tablename" and then I go through the entries until it finds the given name.... alternatively, what I could do is use... select * from tablename where name = 'example'; I was also wondering... whether my approach is appropriate and efficient for searching large databases... or are there better (yet simple) approaches? |
|
|
|
|
|
#2 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 154
Rep Power: 3
![]() |
Quote:
|
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
I suggest your alternative approach, but make sure you take the case sensitivity into consideration. Depending on how you query the database, normally you could determine if the query yielded any results based on how many records were returned from the query.
The "already exists" error is something that can be handled also, again, depending on how you are connection to the database and which method you are using to submit transactions.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 154
Rep Power: 3
![]() |
Quote:
what I was asking is what does it do when I execute the below command using C# select * from tablename where name = 'example'; I know I am not saying it in a very clear way... |
|
|
|
|
|
|
#5 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,054
Rep Power: 5
![]() |
If you're using VS.NET 2005, you might consider using the wizards for the table adapter, etc stuff. Then you can create your queries with the wizard as well, or enter the actual SQL statements if you're comfortable with that. Then, when you execute your select query, you get a table filled with zero or more records. Simply count the number of rows (ie records), and you know whether anything was returned.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() ![]() |
"then if there is no 'example' entry in name column, then what does it return to C#, that I could check against?"
Execute the query using an invalid value for the name, then print out what the resulting value is (probably null), and note the Exception returned. There may also be a mysql_fetch_row type of function that will yield 0 or null based on the results of the query that is passed in. If time permits, I'll tinker with it a bit when I get home and respond with a more descriptive answer.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#7 | |
|
Newbie
Join Date: May 2007
Posts: 3
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| critical: pls help: MySql Database with ASP.NET and C# | paulchwd | ASP.NET | 1 | Apr 16th, 2007 3:51 AM |
| Problem accessing MySQL database | MrMan9879 | PHP | 9 | Mar 23rd, 2006 8:47 AM |
| How to connect MySQL DataBase with ASP.NET | lucifer | C# | 2 | Mar 14th, 2006 7:09 PM |
| mySQL: Changing unique database to fulltext | BAS1X | PHP | 2 | Oct 24th, 2005 9:14 PM |
| Mysql search question? | dmorales | PHP | 15 | Apr 25th, 2005 2:08 PM |