当我尝试运行代码时,遇到问题,当我将PASSWORD =''设置为下面的代码时,所有代码运行良好。SQL问题 - 不读取NULL值
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;
}
但是,当我改变PASSWORD=NULL
我与SQL函数,它显示的错误"Reset Password Failed"
。它只是读取空字符串,而不是NULL值。为什么会发生?
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);
}
}
你调试过了吗?而且您还需要添加SP –
的代码抛出的异常是什么? –
如果你看看你实际创建的SQL,它会读取'SET PASWORD = NULLWHERE Employee_Id = ...'。 –