![]() |
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? |
Quote:
|
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. |
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... |
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.
|
"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. |
Quote:
|
| All times are GMT -5. The time now is 4:51 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC