0% found this document useful (0 votes)
65 views2 pages

Using Using Using Using Using Using Namespace Public Class New

This document contains code for a login form application in C# that connects to a SQL Server database named "STUDENT". It defines a form class with methods for loading the form, handling the login button click, and exiting. When the login button is clicked, it queries the database to validate the username and password, and displays a message on success or invalid login.

Uploaded by

Aya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views2 pages

Using Using Using Using Using Using Namespace Public Class New

This document contains code for a login form application in C# that connects to a SQL Server database named "STUDENT". It defines a form class with methods for loading the form, handling the login button click, and exiting. When the login button is clicked, it queries the database to validate the username and password, and displays a message on success or invalid login.

Uploaded by

Aya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

using System;  
2. using System.Collections.Generic;  
3. using System.ComponentModel;  
4. using System.Data;  
5. using System.Drawing;  
6. using System.Linq;  
7. using System.Text;  
8. using System.Windows.Forms;  
9. using System.Data.Sql;  
10. using System.Data.OleDb;  
11. using System.Data.SqlClient;  
12.   
13. namespace login_form  
14. {  
15.     public partial class Form1 : Form  
16.     {  
17.         SqlConnection con = new SqlConnection();  
18.         public Form1()  
19.         {  
20.             SqlConnection con = new SqlConnection();  
21.             con.ConnectionString = "Data Source=KRISHNA-
PC\\SQLEXPRESS;Initial Catalog=STUDENT;Integrated Security=Tru
e";  
22.   
23.             InitializeComponent();  
24.         }  
25.   
26.         private void Form1_Load(object sender, EventArgs e)  
27.         {  
28.             // TODO: This line of code loads data into the 'sT
UDENTDataSet.login' table. You can move, or remove it, as needed.  
29.             //this.loginTableAdapter.Fill(this.sTUDENTDat
aSet.login);  
30.             SqlConnection con = new SqlConnection("Data Source
=KRISHNA-PC\\SQLEXPRESS;Initial Catalog=STUDENT;Integrated Security=
True");  
31.             con.Open();  
32.   
33.             {  
34.             }  
35.         }  
36.   
37.         private void button1_Click(object sender, EventAr
gs e)  
38.         {  
39.             SqlConnection con = new SqlConnection();  
40.             con.ConnectionString = "Data Source=KRISHNA-
PC\\SQLEXPRESS;Initial Catalog=STUDENT;Integrated Security=True";  
41.             con.Open();  
42.             string userid = textBox1.Text;  
43.             string password = textBox2.Text;  
44.             SqlCommand cmd = new SqlCommand("select userid,pas
sword from login where userid='" + textBox1.Text + "'and password='" 
+ text            Box2.Text + "'", con);  
45.             SqlDataAdapter da = new SqlDataAdapter(cmd);  
46.             DataTable dt = new DataTable();  
47.             da.Fill(dt);  
48.             if (dt.Rows.Count > 0)  
49.             {  
50.                 MessageBox.Show("Login sucess Welcome to Homep
age http://krishnasinghprogramming.nlogspot.com");  
51.                 System.Diagnostics.Process.Start("http://
krishnasinghprogramming.blogspot.com");  
52.             }  
53.             else  
54.             {  
55.                 MessageBox.Show("Invalid Login please che
ck username and password");  
56.             }  
57.             con.Close();  
58.         }  
59.   
60.         private void button2_Click(object sender, EventArgs e) 
 
61.         {  
62.             Application.Exit();  
63.   
64.         }  
65.     }  
66. }  

You might also like