Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- namespace finalproject
- {
- public partial class login : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- lblErrorMessage.Visible = false;
- }
- protected void btnLogin_Click(object sender, EventArgs e)
- {
- using (SqlConnection sqlcon = new SqlConnection("Data Source=DESKTOP-QMMKITS;Initial Catalog=login"))
- {
- sqlcon.Open();
- string query = "SELECT COUNT(1) FROM TableUser WHERE username=@username AND password=@password";
- SqlCommand sqlCmd = new SqlCommand(query, sqlcon);
- sqlCmd.Parameters.AddWithValue("@username", txtUserName.Text.Trim());
- sqlCmd.Parameters.AddWithValue("@password", txtPassword.Text.Trim());
- int count = Convert.ToInt32(sqlCmd.ExecuteScalar());
- if(count == 1)
- {
- Session["username"] = txtUserName.Text.Trim();
- Response.Redirect("test.aspx");
- }
- else
- {
- lblErrorMessage.Visible = true;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment