I posted this a few days ago How to know a row's value before its inserted in gridview? and i got this answer
SqlCommand cmdEvent = new SqlCommand("SELECT COUNT(date) FROM patients WHERE date= '2012/02/23'", yourSqlConnection);
object myCount;
if (yourSqlConnection.State == ConnectionState.Closed){ yourSqlConnection.Open(); }
myCount = cmdEvent.ExecuteScalar();
if (yourSqlConnection.State == ConnectionState.Open){ yourSqlConnection.Close(); }
if (myCount != null)
{
if ((int)myCount >= 10)
{
// Logic here e.g myLabel.Text = "You have reached your maximum of 10 visits!";
return;
}
}
But now i dont need one row's value before its inserted, instead, i need to know the values of 2 rows and i have no idea of how to do it. Im trying to make a login and i need the user's id to make the session unique but i need also to validate if that query returns true and i did it as follow:
comando = new SqlCommand("SELECT user_name FROM login WHERE user_name=@user AND pass=@pass", conexion);
comando.Parameters.AddWithValue("@pass", Upass);
comando.Parameters.AddWithValue("@user", user);
object check_coincidence = comando.ExecuteScalar();
if ((string)check_coincidence == user)
{
Session["USER"] = check_coincidence;
Response.Redirect("someURL")
}
But i do not know how to gat the user's ID to make the session unique, i mean, take that value as a new session.