Login.cs
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 user_login
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=ASP4-PC\SQLEXPRESS;Initial Catalog=comsoul1;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("Select * from comsoul_registration where Fname = '"+txtUser.Text+"' and Password = '"+txtPass.Text+"'", con );
SqlDataReader reader = cmd.ExecuteReader();
int count = 0;
while(reader.Read())
{
count += 1;
}
if (count == 1)
{
MessageBox.Show("OK");
Registraion f2 = new Registraion();
f2.Show();
}
else if(count > 0){
MessageBox.Show("Doublicate user and Password");
}
else{
MessageBox.Show("UserName and Password not correct");
}
txtUser.Clear();
txtPass.Clear();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Registraion.cs
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.Sql;
using System.Data.SqlClient;
namespace user_login
{
public partial class Registraion : Form
{
//C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE
string path = @"Data Source=ASP4-PC\SQLEXPRESS;Initial Catalog=comsoul1;Integrated Security=True";
public Registraion()
{
InitializeComponent();
}
private void btnregister_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(path);
if (con.State != ConnectionState.Open)
{
con.Open();
string addquery = string.Format("insert into comsoul_registration (Fname,Lname, Phone, Street, Zip_code, Email, Password,Re_enter, Creadit_card,Creadit_card_type,Date_Time) values('" +
txtFname.Text + "','" + txtLname.Text + "','" + txtPhone.Text + "', '" + txtStreet.Text + "', '" + txtZip.Text + "','" + txtEmail.Text + "','" + txtPassword.Text + "', '" + txtRepassword.Text + "','" + txtCcard.Text + "','" + txtCcard2.Text + "','" + txtdate.Value.Date + "')");
SqlCommand cmd = new SqlCommand(addquery,con);
var roweffected = cmd.ExecuteNonQuery();
MessageBox.Show("Inserted Data !");
txtFname.Text = null;
txtLname.Text = null;
txtPhone.Text = null;
txtStreet.Text = null;
txtZip.Text = null;
txtEmail.Text = null;
txtPassword.Text = null;
txtRepassword.Text = null;
txtCcard.Text = null;
txtCcard2.Text = null;
}
else
{
con.Close();
}
}
private void btncancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
database
create database comsoul1
create table comsoul_registration
(
id int primary key identity,
[Fname] varchar (50),
[Lname] varchar (50),
[Phone] int,
[Street] varchar (50),
[City] varchar (50),
[Zip_code] int,
[Email] varchar (50),
[Password] varchar (50),
[Re-enter] varchar (50),
[Creadit_card] int,
[Creadit_card_type] varchar (50),
)
alter table comsoul_registration
add [Date_Time] datetime
select * from comsoul_registration
No comments:
Post a Comment