•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 392,091 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,933 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser:
Views: 4776 | Replies: 15
![]() |
•
•
Join Date: Aug 2007
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
OK this is what I want to do:
A program like this has alreadh been created, its called FS ACARS that program also has some other cool functions, that I dont need.
The problem I am having trouble with is when the user enters there user name and password into 2 different text boxes, how do I check that information with the database?
So an example:
User name [ txtbox1 ] Password [ txtbox2 ]
I need to search the database to find that txtbox1.text is a valid user name. and if so, does txtbox2.text = the corresponding password?
I hope this is enough detail!
Thanks ahead of time!!!!
- Log the User in by checking with a SQL Database with a table that has user name and password. Also that table is linked to another table with all there personal information
- After they login, they have to enter information into the field and send it to the database or they can get presetsfrom a database and and edit them if need be. From there they will send there specific information to a diffrent table which will contain there data.
A program like this has alreadh been created, its called FS ACARS that program also has some other cool functions, that I dont need.
The problem I am having trouble with is when the user enters there user name and password into 2 different text boxes, how do I check that information with the database?
So an example:
User name [ txtbox1 ] Password [ txtbox2 ]
I need to search the database to find that txtbox1.text is a valid user name. and if so, does txtbox2.text = the corresponding password?
I hope this is enough detail!
Thanks ahead of time!!!!
Send the text of those two text boxes as arguments to a stored procedure. The stored procedure should check if the username exists and the password matches. Something like this I guess.
In your C# program you can run it like this.
create procedure ValidateUserLogin
@UserName varchar(30)
, @Password varchar(30)
as
begin
if exists (select * from UsersTable as ut
where ut.UserName = @UserName AND ut.Password = @Password)
select 1;
else
select 0;
end c# Syntax (Toggle Plain Text)
private bool IsValidatedUser( string username, string password ) { try { bool rv = false; using ( SqlConnection con = new SqlConnection( connectionString ) ) { using ( SqlCommand cmd = new SqlCommand() ) { con.Open(); cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "ValidateUserLogin"; cmd.Parameters.Add( "@UserName", SqlDbType.VarChar, 30 ).Value = username; cmd.Parameters.Add( "@Password", SqlDbType.VarChar, 30 ).Value = password; rv = Convert.ToBoolean( cmd.ExecuteScalar() ); con.Close(); } } return rv; } catch ( Exception ex ) { // Log errors throw; } }
The truth does not change according to our ability to stomach it.
•
•
Join Date: Aug 2007
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
Error 1 } expected 19 10 Costal
Error 2 Type or namespace definition, or end-of-file expected 68 5 Costal
And I am kinda confused on a couple of things:
1. Where do I put the C# code... would it go into the button_1 click event handler. OR should that be its own class??
How does it grab the data from the text boxes to validate it?
Error 2 Type or namespace definition, or end-of-file expected 68 5 Costal
And I am kinda confused on a couple of things:
1. Where do I put the C# code... would it go into the button_1 click event handler. OR should that be its own class??
How does it grab the data from the text boxes to validate it?
•
•
•
•
Where do I put the C# code...
The truth does not change according to our ability to stomach it.
•
•
Join Date: Aug 2007
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
Ok here goes:
I have a button with two text boxes above it on its own form.
The button says OK. after the user enters his/her username & Password they click thte ok button and it validates them.
On the database side I have a .mdf file with 1 table in it that has three columns. UserName Password and userID. The UserID is for me its an identity column so i can keep track of users.
I also have the procedure you gave me above.
Where do i begin?
I know i need to get the data from the textboxes. and put them into variables.
then send them to the procedure to check in the database
then the procedure needs to send back to code. and change a bool variable to true... or give an error.
Thats what I know.. am I missing anything?
I have a button with two text boxes above it on its own form.
The button says OK. after the user enters his/her username & Password they click thte ok button and it validates them.
On the database side I have a .mdf file with 1 table in it that has three columns. UserName Password and userID. The UserID is for me its an identity column so i can keep track of users.
I also have the procedure you gave me above.
Where do i begin?
I know i need to get the data from the textboxes. and put them into variables.
then send them to the procedure to check in the database
then the procedure needs to send back to code. and change a bool variable to true... or give an error.
Thats what I know.. am I missing anything?
I guess you could just put the method in the form class. Then you call it in the button's click event.
c# Syntax (Toggle Plain Text)
void buttonOK_Click( object sender, EventArgs e ) { bool isValid = this.IsValidatedUser( this.textBoxUserName.Text , this.textBoxPassword.Text ); if ( isValid ) { // Do whatever for a valid login } else { // Show an error for an invalid login } }
The truth does not change according to our ability to stomach it.
•
•
Join Date: Aug 2007
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
Error 1 The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?) 17 24 Costal
Error 2 The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?) 17 48 Costal
Error 3 The name 'connectionString' does not exist in the current context 17 62 Costal
Error 4 The type or namespace name 'SqlCommand' could not be found (are you missing a using directive or an assembly reference?) 20 28 Costal
Error 5 The type or namespace name 'SqlCommand' could not be found (are you missing a using directive or an assembly reference?) 20 49 Costal
Error 6 The name 'CommandType' does not exist in the current context 27 43 Costal
Error 7 The name 'SqlDbType' does not exist in the current context 31 57 Costal
Error 8 The name 'SqlDbType' does not exist in the current context 33 57 Costal
I get all these errors?
What I did:
I made a new class file and put that method into the class. Is this what you meant or did you want me to put it into the program.cs file or put it into the form1.cs file?
Error 2 The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?) 17 48 Costal
Error 3 The name 'connectionString' does not exist in the current context 17 62 Costal
Error 4 The type or namespace name 'SqlCommand' could not be found (are you missing a using directive or an assembly reference?) 20 28 Costal
Error 5 The type or namespace name 'SqlCommand' could not be found (are you missing a using directive or an assembly reference?) 20 49 Costal
Error 6 The name 'CommandType' does not exist in the current context 27 43 Costal
Error 7 The name 'SqlDbType' does not exist in the current context 31 57 Costal
Error 8 The name 'SqlDbType' does not exist in the current context 33 57 Costal
I get all these errors?
What I did:
I made a new class file and put that method into the class. Is this what you meant or did you want me to put it into the program.cs file or put it into the form1.cs file?
You need to add the SqlClient reference to your project and add a using statement wherever you use those classes.
You need to store the connection string somewhere, that's what connectionString is; a variable in your application that stores a SQL connection string.
c# Syntax (Toggle Plain Text)
using System.Data.SqlClient;
The truth does not change according to our ability to stomach it.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C# Marketplace
- built in login and createuser wizard but for a remote SQL database? how to change? (ASP.NET)
- SQL Database loop (C#)
- Insert into sql database (ASP.NET)
- Perl Database Login Package Help Wanted (Perl)
- Process very slow - SQL Database (MS SQL)
- urgent: session timeout occurs unexpectedly(given both web.config & global.asax code) (ASP.NET)
- Help with Roles Stored in SQL database (ASP.NET)
- Snyc'n Local SQL database online (MS SQL)
- need help creating user defined SQL statement (ASP.NET)
- SQL not a trusted connection?! (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: how to convert typed dataset to untyped dataset???
- Next Thread: Reading data from a Label Control


Linear Mode