로그인 양식이 있고 다른 상황의 코드가 수정되어 상황에 맞게 작동합니다. 숫자가 비어 있거나 '무한'하므로 로그인이 유효하지 않은 경우 오류가 표시됩니다. 내가 처리 오류에 대한 갈 것이라고 어떻게로그인이 유효하지 않습니다. 지정한 캐스트가 유효하지 않습니다.
Results = (int)cmdselect.Parameters["@OutRes"].Value;
그것은 코드가 여기에 잘못된 로그인을 트리거하는 유효한 정수가 아닌 너무 때 :
public int Validate_Login(String Username, String Password)
{
//SqlConnection con = new SqlConnection(@"User id=judgment_day;Password=Kit$hen;Server=216.40.232.82, 2153;Database=new_judgment-system");
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CityCollectionCSharp.Properties.Settings.newCityCollectionConnectionString"].ConnectionString);
SqlCommand cmdselect = new SqlCommand();
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.CommandText = "[dbo].[prcLoginv]";
cmdselect.Parameters.Add("@Username", SqlDbType.VarChar, 50).Value = Username;
cmdselect.Parameters.Add("@UPassword", SqlDbType.VarChar, 50).Value = Password;
cmdselect.Parameters.Add("@OutRes", SqlDbType.Int, 4);
cmdselect.Parameters["@OutRes"].Direction = ParameterDirection.Output;
cmdselect.Connection = con;
int Results = 0;
try
{
con.Open();
cmdselect.ExecuteNonQuery();
Results = (int)cmdselect.Parameters["@OutRes"].Value;
}
catch (SqlException ex)
{
lblMessage.Text = ex.Message;
}
finally
{
cmdselect.Dispose();
if (con != null)
{
con.Close();
}
}
return Results;
}
오류는이 라인에서 발생합니다 :
protected void btnlogin_Click(object sender, EventArgs e)
{
int Results = 0;
if (txtUsername.Text != null && txtPassword.Text != null)
{
Results = Validate_Login(txtUsername.Text, txtPassword.Text);
if (Results > 0)
{
lblMessage.Text = "Login is Good";
GlobalVariables.Globals.SetGlobalInt(Results);
lblMessage.Text = "'" + GlobalVariables.Globals.GlobalInt + "'";
this.Hide();
frmSwitch frm = new frmSwitch();
frm.Show();
}
else
{
lblMessage.Text = "Invalid Login";
lblMessage.ForeColor = System.Drawing.Color.Red;
}
}
else
{
lblMessage.Text = "Please make sure that the username and the password is Correct";
}
}
감사합니다. 카미. 나는 게으르다가 if 문을 잊었다 고 생각한다. 이것은 원래 0 또는 1로 설정되었지만 소프트웨어의 다른 부분에 실제 정보를 전달하고 중요한 부분을 놓칠 필요가있었습니다. 감사! – korrowan