0
我張貼這幾天前How to know a row's value before its inserted in gridview? 和我得到這個答案如何知道行值sql server asp.net?
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;
}
}
但現在我不需要一個行的值之前其插入,相反,我需要了解的2行中的值,我沒有如何去做的想法。 我試着做一個登錄名和我需要的用戶的ID進行會話獨一無二的,但我也需要驗證,如果該查詢返回true,我做了如下:
comando = new SqlCommand("SELECT user_name FROM login WHERE [email protected] AND [email protected]", 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")
}
但我不知道如何gat用戶的ID以使會話具有唯一性,我的意思是,將該值作爲新會話。
THANX MEN!我真的很高興! – Misters 2013-02-25 23:27:57