Another Simple Code for Login Form in C#
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DE_EXPERIMENT
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection Con;
Con = new SqlConnection(@"Data Source=DESKTOP-L87DR27;Initial Catalog=Experiment;Integrated Security=True");
SqlCommand Cmd = new SqlCommand("select * from Exp where username = @username and password = @password", Con);
Cmd.Parameters.AddWithValue("@username", textBox3.Text);
Cmd.Parameters.AddWithValue("@password", textBox4.Text);
Con.Open();
SqlDataReader dr = Cmd.ExecuteReader();
if (dr.HasRows == true)
{
MessageBox.Show("Okay");
}
else
{
MessageBox.Show("okay no");
}
Con.Close();
}
}
}
Post a Comment