我面臨以下j問題:我在Access 2010上有一個數據庫,字段爲NIC
,Active
和Page
,都是數字類型。我想要創建一個登錄頁面,將NIC
(數字)作爲用戶的輸入,然後根據其NIC將其重定向到特定頁面。登錄頁面驗證NIC號碼
不同的人會看到不同的頁面..我得到一個錯誤在ExecuteScalar
命令,也許我的查詢是不正確的或可能ExecuteScalar
不能持有查詢...我收到data type mismatch
錯誤。
try
{
FirsstPage f = new FirsstPage();
SecondPage second = new SecondPage();
oledcon.Open();
string NIc = (TextBox1.Text);
// string query = "select * from LogINTable where NIC='" + NIc + "'AND Active=0 AND page=1";
//string query = "select * from LogINTable where NIC='" + nic + "'AND Active=0";
string query = "SELECT * FROM LogINTable WHERE NIC= '" + NIc + "' AND Active=0 AND page=1";
//string query = "select
OleDbCommand comm = new OleDbCommand(query,oledcon);
string a = (string) comm.ExecuteScalar();
if (a != null)
{
Response.Redirect("FirsstPage.aspx");
string update = "update into LogINTable Active='1' where NIC='" + NIc + "' ";
//OleDbCommand com = new OleDbCommand();
//int b = Convert.ToInt32(com.ExecuteScalar());
}
else
{
Response.Redirect("SecondPage.aspx");
string update = "update into LogINTable Active='1' where NIC='" +NIc + "' ";
}
oledcon.Close();
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
finally
{
oledcon.Close();
}
我或多或少地重寫了你的整個問題,使其實際可讀,刪除所有* l33t sp34k *等。如果你想讓人們花時間做出迴應,如果他們必須先花5分鐘時間來理解他們不太願意提供幫助的問題,那麼請注意演示。 – 2013-05-13 09:20:19
「SELECT *」幾乎總是一個壞主意(除了'EXISTS()'子句),特別是在這裏,你只需要一列的值 – 2013-05-13 09:21:30
如果這個'NIC'列是數字,你爲什麼要把該值在引號中? – 2013-05-13 11:47:53