Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 27th, 2007, 3:01 AM   #1
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 154
Rep Power: 3 programmingnoob is on a distinguished road
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"
on C#....
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';
but then I dont know how C# would catch it if mysql tells it that it matched nothing, which implies empty set.


I was also wondering... whether my approach is appropriate and efficient for searching large databases... or are there better (yet simple) approaches?
programmingnoob is offline   Reply With Quote
Old Jun 27th, 2007, 3:09 AM   #2
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 154
Rep Power: 3 programmingnoob is on a distinguished road
Quote:
Originally Posted by programmingnoob View Post
but then I dont know how C# would catch it if mysql tells it that it matched nothing, which implies empty set.


I was also wondering... whether my approach is appropriate and efficient for searching large databases... or are there better (yet simple) approaches?
I mean for example, while inserting an entry into mysql, it can catch for exception and determine if error number is 1062, then the entry already exists....
programmingnoob is offline   Reply With Quote
Old Jun 27th, 2007, 9:04 AM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,436
Rep Power: 7 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Jun 27th, 2007, 11:31 AM   #4
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 154
Rep Power: 3 programmingnoob is on a distinguished road
Quote:
Originally Posted by Infinite Recursion View Post
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.
oh I know how to deal with 'already exists' error....
what I was asking is what does it do when I execute the below command using C#
select * from tablename where name = 'example';
then if there is no 'example' entry in name column, then what does it return to C#, that I could check against?
I know I am not saying it in a very clear way...
programmingnoob is offline   Reply With Quote
Old Jun 27th, 2007, 2:34 PM   #5
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 864
Rep Power: 3 lectricpharaoh is on a distinguished road
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.
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp
lectricpharaoh is offline   Reply With Quote
Old Jun 27th, 2007, 3:07 PM   #6
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,436
Rep Power: 7 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
"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."
Infinite Recursion is offline   Reply With Quote
Old Jun 27th, 2007, 5:55 PM   #7
Fourth
Newbie
 
Join Date: May 2007
Posts: 3
Rep Power: 0 Fourth is an unknown quantity at this point
Quote:
Originally Posted by Infinite Recursion View Post
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.
this is the answer to my knowledge. at least in my experience with asking for things in a database in mysql the return of an empty result is null.
Fourth is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:43 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC