using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection("Data source= HP-PC\\SQLEXPRESS;Initial Catalog=Login_data;Integrated Security=True;");
public Form1() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
try {
String s;
con.Open();
SqlCommand com = new SqlCommand("select *from Login_info where U_name=@User_name AND U_password = @Password", con);
com.Parameters.AddWithValue("@User_name", textBox1.Text);
com.Parameters.AddWithValue("@Password", textBox2.Text);
SqlDataReader rd = com.ExecuteReader();
if (rd.Read())
{
s = rd.GetString(0);
MessageBox.Show("Welcome" + textBox1.Text, "Welcome", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); }
else {
MessageBox.Show("incorrect Username or password \n please enter correct username and password.", "Login failed", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
con.Close();
}
catch {
MessageBox.Show("Database connection failure", "error",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}}}}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
static class Program
{
static void main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}}}
namespace WindowsFormsApplication3
partial class Form1
{
private System.ComponentModel.IContainer components =null;
protected override void Dispose(bool disposing)
{
if(disposing && (components !=null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.textBox1=new System.Windows.Forms.TextBox();
this.textBox2=new System.Windows.Forms.TextBox();
this.button1=new System.Windows.Forms.Button();
this.label1=new System.Windows.Forms.Label();
this.label2=new System.Windows.Forms.Label();
this.SuspendLayout();
this.textBox1.Location=new System.Drawing.Point(95,23);
this.textBox1.Name="textBox1";
this.textBox1.Size=new System.Drawing.Size(311,20);
this.textBox1.TabIndex=0;
this.textBox2.Location=new System.Drawing.Point(95,64);
this.textBox2.Name="textBox2";
this.textBox2.Size=new System.Drawing.Size(311,20);
this.textBox2.TabIndex=1;
this.button1.Location=new System.Drawing.Point(313,90);
this.button1.Name="button1";
this.button1.Size=new System.Drawing.Size(81,23);
this.button1.TabIndex=2;
this.button1.Text="Login>>";
this.button1.UseVisualStyleBackColor=true;
this.button1.Click +=new System.EventHandler(button1_Click);
this.label1.AutoSize=true;
this.label1.Location=new System.Drawing.Point(23,26);
this.label1.Name="label1";
this.label1.Size=new System.Drawing.Size(56,13);
this.label1.TabIndex=4;
this.label1.Text="Password";
this.AutoScaleDimensions= new System.Drawing.SizeF(6F,13F);
this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize=new System.Drawing.Size(428,121);
this.Controls.Add(this.label1);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.button1);
this.Name="Form1";
this.Text="Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection("Data source= HP-PC\\SQLEXPRESS;Initial Catalog=Login_data;Integrated Security=True;");
public Form1() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
try {
String s;
con.Open();
SqlCommand com = new SqlCommand("select *from Login_info where U_name=@User_name AND U_password = @Password", con);
com.Parameters.AddWithValue("@User_name", textBox1.Text);
com.Parameters.AddWithValue("@Password", textBox2.Text);
SqlDataReader rd = com.ExecuteReader();
if (rd.Read())
{
s = rd.GetString(0);
MessageBox.Show("Welcome" + textBox1.Text, "Welcome", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); }
else {
MessageBox.Show("incorrect Username or password \n please enter correct username and password.", "Login failed", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
con.Close();
}
catch {
MessageBox.Show("Database connection failure", "error",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}}}}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
static class Program
{
static void main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}}}
namespace WindowsFormsApplication3
partial class Form1
{
private System.ComponentModel.IContainer components =null;
protected override void Dispose(bool disposing)
{
if(disposing && (components !=null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.textBox1=new System.Windows.Forms.TextBox();
this.textBox2=new System.Windows.Forms.TextBox();
this.button1=new System.Windows.Forms.Button();
this.label1=new System.Windows.Forms.Label();
this.label2=new System.Windows.Forms.Label();
this.SuspendLayout();
this.textBox1.Location=new System.Drawing.Point(95,23);
this.textBox1.Name="textBox1";
this.textBox1.Size=new System.Drawing.Size(311,20);
this.textBox1.TabIndex=0;
this.textBox2.Location=new System.Drawing.Point(95,64);
this.textBox2.Name="textBox2";
this.textBox2.Size=new System.Drawing.Size(311,20);
this.textBox2.TabIndex=1;
this.button1.Location=new System.Drawing.Point(313,90);
this.button1.Name="button1";
this.button1.Size=new System.Drawing.Size(81,23);
this.button1.TabIndex=2;
this.button1.Text="Login>>";
this.button1.UseVisualStyleBackColor=true;
this.button1.Click +=new System.EventHandler(button1_Click);
this.label1.AutoSize=true;
this.label1.Location=new System.Drawing.Point(23,26);
this.label1.Name="label1";
this.label1.Size=new System.Drawing.Size(56,13);
this.label1.TabIndex=4;
this.label1.Text="Password";
this.AutoScaleDimensions= new System.Drawing.SizeF(6F,13F);
this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize=new System.Drawing.Size(428,121);
this.Controls.Add(this.label1);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.button1);
this.Name="Form1";
this.Text="Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
}
}
OUTPUT
CLICK TO DOWNLOAD
No comments:
Post a Comment