Developing a window based login form in C Sharp .Net is a little different from what we have done for VB.Net and Vb6,Here you do not have built in login form so you have to design a simple login form with two text boxes, labels and command buttons.Following screen shot will show you a simple layout
Specifying Connection String:
In order to use “SqlClient” you have to use System.Data.SqlClient namespace following code will show you how to do it.
Now you can use SqlClient for connection,dataset e.t.c what ever you like. Double click OK button and write following code:
SqlConnection sconn = new SqlConnection("User ID=Username;Password=Password;Initial Catalog=DB Name;Data Source=ServerName/IP");
Form1 formOne = new Form1();
Successful SuccessForm = new Successful();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from users where username ='" + TxtUsr.Text + "' and password='" + TxtPwd.Text + "'", sconn);
int count = ds.Tables.Rows.Count;
this.Visible = false;
SuccessForm.Visible = true;
The above code will first connect to the SQL Server 2000 database and then object of two forms “Form1″ and “Successful” as “formOne” and “SuccessForm” are initialized then all the operation with the database in order to validate the supplied “username” and “password” if the supplied username and password is correct then “SuccessForm” will be displayed otherwise following message box will be displayed:
In order to close this form double cancel button and write following code:
Hope you have enjoyed this tutorial do not forget to give your feed back.
CodeReflex is your foremost source of design practices, coding techniques and quality testing. Over here, you will get the solution of every known issue relevant to programming in mostly all of the top languages. Not only this but you can also download the code snippets by experts and freely incorporate into your project.