protected void btn_login_Click(object sender, EventArgs e) { string strCon = ConfigurationManager.ConnectionStrings["ConnectionStringusers"].ConnectionString; string strSelect = "SELECT COUNT(*) FROM [Users] WHERE UserName = @Username AND Password = @Password"; SqlConnection con = new SqlConnection(strCon); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = strSelect; SqlParameter username = new SqlParameter("@Username", SqlDbType.VarChar, 50); username.Value = username_id.Value.Trim().ToString(); cmd.Parameters.Add(username); SqlParameter password = new SqlParameter("@Password", SqlDbType.VarChar, 50); password.Value = password_id.Value.Trim().ToString(); cmd.Parameters.Add(password); con.Open(); int result = (Int32)cmd.ExecuteScalar(); con.Close(); if (result >= 1) { Response.Redirect("kreu.aspx"); Session["username"] = username_id.Value; } else Response.Write(@"<script language='javascript'>alert('Invalid username or password!') </script>"); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)