I have learnt how to send a user ID from table and pass it on as QueryString but I also tried to send another data from other column in the table but I could not.
Please can someone help me?
Code
protected void Button1_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtUsername.Text) && !string.IsNullOrEmpty(txtPassword.Text))
{
string Uid = string.Empty;
using (SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security = True"))
{
string check = "SELECT Uid FROM Users WHERE pass = @pass COLLATE SQL_Latin1_General_CP1_CS_AS AND email = @email";
using (SqlCommand com = new SqlCommand(check, con))
{
com.CommandType = CommandType.Text;
com.Parameters.AddWithValue("@email", txtUsername.Text.Trim());
com.Parameters.AddWithValue("@pass", txtPassword.Text.Trim());
con.Open();
Uid = Convert.ToString(com.ExecuteScalar());
con.Close();
}
if (!string.IsNullOrEmpty(Uid))
{
string users = string.Empty;
using (SqlCommand cmd = new SqlCommand("SELECT Uid FROM UserActivation WHERE Uid = @Uid", con))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Uid", Uid);
con.Open();
users = Convert.ToString(cmd.ExecuteScalar());
con.Close();
}
if (!string.IsNullOrEmpty(users))
{
Session["user"] = users;
string query = "SELECT LastLogin from Users WHERE Uid = @Uid";
using (SqlCommand cmd = new SqlCommand(query, con))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Uid", Session["user"]);
con.Open();
Session["LastLogin"] = Convert.ToDateTime(cmd.ExecuteScalar());
con.Close();
}
string UpdateLog = @"UPDATE Users SET LastLogin=GETDATE(), IsActive=1 WHERE Uid = @Uid";
using (SqlCommand cmd = new SqlCommand(UpdateLog, con))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Uid", users);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
Response.Redirect("Page2.aspx?Id=" + users);
}
else
{
dvMessage.Visible = true;
lblMessage.Visible = true;
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "Account has not been activated";
txtPassword.Text = "";
txtPassword.Focus();
}
}
else
{
dvMessage.Visible = true;
lblMessage.Visible = true;
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "Invalid Login Details";
txtPassword.Text = "";
txtPassword.Focus();
}
}
}
else
{
dvMessage.Visible = true;
lblMessage.Visible = true;
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "All Fields are Required";
}
}