You are on page 1of 1

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace Ecom
{
public partial class Login : System.Web.UI.Page
{
static string connString = @"Data Source=LAPTOP-TP8GSGH2\SQLEXPRESS;Initial
Catalog=Ecomapi;Integrated Security=True";
SqlConnection conn = new SqlConnection(connString);
protected void Page_Load(object sender, EventArgs e)
{

protected void btnLogin_Click(object sender, EventArgs e)


{
{

SqlCommand cmd = new SqlCommand("select * from Login where Email=@username and Pass
word=@word", conn);  
        cmd.Parameters.AddWithValue("@username", txtUsername.Text);  
        cmd.Parameters.AddWithValue("@word", txtPassword.Text);  
        SqlDataAdapter sda = new SqlDataAdapter(cmd);  
        DataTable dt = new DataTable();  
        sda.Fill(dt);  
        conn.Open();  
        int i = cmd.ExecuteNonQuery();  
        conn.Close();  
  
        if (dt.Rows.Count > 0) {  
            Response.Redirect("Product.aspx");  
        } else {  
            Label1.Text = "Your username and word is incorrect";  
            Label1.ForeColor = System.Drawing.Color.Red;  
  
        }
}
}
}
}

You might also like