0% found this document useful (0 votes)
24 views

Using System

The document contains code for a C# login form application. It includes code to connect to a database, query for a user, and check login credentials on button click before closing or showing an error.

Uploaded by

19110202
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)
24 views

Using System

The document contains code for a C# login form application. It includes code to connect to a database, query for a user, and check login credentials on button click before closing or showing an error.

Uploaded by

19110202
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/ 3

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Data.SqlClient;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace Login_Form

public partial class Form1 : Form

public Form1()

InitializeComponent();

private void label1_Click(object sender, EventArgs e)

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)

}
private void btCancel_Click(object sender, EventArgs e)

Close();

private void btLogin_Click(object sender, EventArgs e)

MY_DB db = new MY_DB();

SqlDataAdapter adapter = new SqlDataAdapter();

DataTable table = new DataTable();

SqlCommand command = new SqlCommand("SELECT * FROM LOG_IN WHERE USERNAME =@Y


user AND password = @Pass", db.getConnection);

command.Parameters.Add("@User", SqlDbType.VarChar).Value = TextBoxUserName.Text;

command.Parameters.Add("@Pass", SqlDbType.VarChar).Value = TextBoxPassword.Text;

adapter.SelectCommand = command;

adapter.Fill(table);

if ((table.Rows.Count > 0 ))

this.DialogResult = DialogResult.OK;

else

MessageBox.Show("Invalid Username Or Password", "Login Erreor", MessageBoxButtons.OK,


MessageBoxIcon.Error);

}
private void Form1_Load(object sender, EventArgs e)

pictureBox1.Image = Image.FromFile("1495165872455_600.jpg");

You might also like