我正在處理一個簡單的asp.net登錄頁面。一個簡單的代碼,當用戶登錄時驗證與SQL和直接到頁面的人員或管理員。但我有這個錯誤(int.Parse(myReader.ToString())> 0)...輸入字符串的不正確的格式 我的代碼..輸入字符串的格式不正確c#和asp.net
string Connection = "Data Source=(ip);Initial Catalog=..;Persist Security Info=True;User ID=(id);Password=(pass)";
SqlConnection myConn = new SqlConnection(Connection);
SqlCommand SelectCommand = new SqlCommand("select * from tar_login where Username ='" + txtUsername.Text + "' and Password='" + txtPassword.Text + "' and Position='" + ddlPosition.Text + "';", myConn);
myConn.Open();
var myReader = SelectCommand.ExecuteScalar();
myConn.Close();
if (myReader != null)
{
if (int.Parse(myReader.ToString()) > 0)
{
if (ddlPosition.Text == "Admin")
{
Response.Redirect("manager.aspx");
}
}
}
if (myReader != null)
{
if (int.Parse(myReader.ToString()) > 0)
{
if (ddlPosition.Text == "Staff")
{
Response.Redirect("staff.aspx");
}
}
}
else
{
Label1.ForeColor = System.Drawing.Color.Red;
Label1.Text = "Incorrect. Please try again";
myConn.Close();
}
。幫助作爲即時通訊新的ASP。 net和c#
這意味着'myReader.ToString()'不是一個數,或不的格式是一個int。 – Noctis 2014-08-30 06:55:31
調試你的代碼,在var var myReader = SelectCommand.ExecuteScalar();添加斷點並檢查它的值是什麼,可能不是整數或null – Farrokh 2014-08-30 06:57:57
@Noctis在斷點我得到myReader爲null – Tar7 2014-08-30 07:09:16