I have an issue when I try to run the code, everything runs well when I set my PASSWORD= '' as the code below.
public int ClearEmployeePasswordById(Employee p)
{
int result = -1;
try
{
string sql = "UPDATE EMPLOYEE SET " +
"PASSWORD=''" +
"WHERE Employee_Id=" + p.EmployeeId;
Common.logToFile("PosNet.Data.Sybase.cs", "ClearEmployeePasswordById", sql);
string r = ExecuteNonQuery(sql);
if (!string.IsNullOrEmpty(r))
throw new Exception(r);
result = 1;
InsertAuditLog();
}
catch (Exception ex)
{
Common.logErrorToFile("PosNet.Data.Sybase.cs", "ClearEmployeePasswordById", ex.Message);
//throw ex;
}
return result;
}
But when I change the PASSWORD=NULL
at my function with the sql, it shows the error "Reset Password Failed"
. It just read the empty string but not the NULL value. Why does it happen?
private void btnPasswordReset_Click(object sender, EventArgs e)
{
try
{
string employeeWithoutQuote = lblEmployeeId.Text.Substring(1, 10);
int employeeId = int.Parse(employeeWithoutQuote);
Employee employee = MF.BC.DA.GetEmployeeByBarcode(employeeId);
if (MF.BC.DA.ClearEmployeePasswordById(employee) != 1)
{
throw new Exception("Reset Password Failed");
}
else
{
MessageBox.Show("Reset Password Success");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}