2
I am willing to treat a field in my program to accept data NULL
if this field is not completed, it would be CliDtNasc
.
I did the treatment in class with the if
ternary and in the class properties I treated to check whether the field is NULL
or not, see:
Class:
(!string.IsNullOrEmpty(CliDtNasc) ? new
SqlParameter("@CliDtNasc",DateTime.Parse(CliDtNasc)) : new
SqlParameter("@CliDtNasc",DBNull.Value))`
Code Behind:
if (txtDtNasc.Text.Length > 0)
{
objCli.CliDtNasc = Convert.ToString(Convert.ToDateTime(txtDtNasc.Text).ToString("yyyy-MM-dd"));
}
Homologation:
I searched the XPTO client that had the date of birth as "03/11/1994".
I erased the date and saved. Debugging I checked that it does not come back as NULL
in the field and, keeps the date. However, when I just modify the date of birth the changing method works.
I already handled the string error. But now it is processing, but it is not allowing the change. No errors.
– Igor Carreiro
You want to replicate the
NULL
correctly to the database, right? Which SQL is running?– Leonel Sanches da Silva
@Ciganomorrisonmendez Correto. I am using SQL Server 2014
– Igor Carreiro
Okay, and what is SQL? Need to ask a question.
– Leonel Sanches da Silva
If you do a direct Insert in the bd works? You are using stored procedures to do the
inserção/alteração
?– Marconi