Comparing 2 values in same column SQL (C#)
-
Hi all. I am busy writing a program, in Microsoft Visual Web Developer, and have a database was several tables. The one I am focusing on now is the ACCOUNT table. This table contains username, password and email column. I want to compare a username entered into a textbox with the existing usernames in the ACCOUNT table, so that I can create a message saying that the entered user already exists. I know how to do this in C# with if statements, but am really unsure with SQL, since not sure how to use it with SELECT.Thanks
-
Hi all. I am busy writing a program, in Microsoft Visual Web Developer, and have a database was several tables. The one I am focusing on now is the ACCOUNT table. This table contains username, password and email column. I want to compare a username entered into a textbox with the existing usernames in the ACCOUNT table, so that I can create a message saying that the entered user already exists. I know how to do this in C# with if statements, but am really unsure with SQL, since not sure how to use it with SELECT.Thanks
-
Hi all. I am busy writing a program, in Microsoft Visual Web Developer, and have a database was several tables. The one I am focusing on now is the ACCOUNT table. This table contains username, password and email column. I want to compare a username entered into a textbox with the existing usernames in the ACCOUNT table, so that I can create a message saying that the entered user already exists. I know how to do this in C# with if statements, but am really unsure with SQL, since not sure how to use it with SELECT.Thanks
Yeah, what Eddy said. But, provided you have a unique index on the column (and you should), it may be more efficient simply to try the INSERT and catch the exception -- you have to do that anyway.
-
Hi all. I am busy writing a program, in Microsoft Visual Web Developer, and have a database was several tables. The one I am focusing on now is the ACCOUNT table. This table contains username, password and email column. I want to compare a username entered into a textbox with the existing usernames in the ACCOUNT table, so that I can create a message saying that the entered user already exists. I know how to do this in C# with if statements, but am really unsure with SQL, since not sure how to use it with SELECT.Thanks
Instead of using 1 in Eddys query use count(*), this will tell you how many records match the name. You should study database design as you may run into some of the basic errors made by newbies. Primary keys and unique constraints.
Never underestimate the power of human stupidity RAH
-
Thanks! :)