c# - Create a login application with local database in visual studio -
I'm having trouble creating a simple login application in C #. I just want to create an entry form and whenever I enter a user name and password, it checks with the database if it exists or not, and since I do not have much information about it, then I do it Can not manage for!
I have created a Windows Forms in VS Express, and have set up a design with a username and password and text box for a login button. Then I added a new element to my project and chose the local database (dataset). In the left, I have two fields: It has the name of the data connection with "database1.sdf", and it has "datasource" with "database 1". I do not know what both of them mean, I've just created a new user table in "Database 1 SDF" and added the ID, username and password column. But after that, only those two elements, I have no clue what I want to do. What code should I write to connect to the database to check prices, and where did I write this code?
I tried to code many codes online, but it does not work: /
I am sorry if my questions seem stupid, but I need your help! Thanks!
This is the snippet of Visual Studio C # coding that I'm doing for a system project The main topic as programmer
Private zeros btnLogin_Click (Object Sender, EventArgs e) {// You may have database location in your database SqlConnection con = new SqlConnection (@ "Data source = ( LocalDB) \ MSSQLLocalDB; AttachDbFilename = H: \ School \ copro3 \ EnrollmentSystemProgram \ EnrollmentSystemProgram \ Login.mdf; Integrated Security = True; "); // You can use your database table and its contents for DataAdapter
SqlDataAdapter sda = New SqlDataAdapter ("SELECT COUNT (*) From tblLogin WHERE user name = '"+ txtUser.Text +"' and password = '"+ + txtPass.Text."' ', Con); DataTable DT = new dataTable (); sda.Fill (DT); if (DT .ro [0] [0]. Ostring () == "1") {this.Hide (); new frmDashboard (). Show ();} and {lblNotify.Show (); LblNotify.Text = "Login Failed "; TxtUser.Text =" "; TxtPass.Text =" ";}} Private Zero frmLogin_Load (object sender, EventArgs e) {lblNotify.Hide ();}
Comments
Post a Comment