NULL field in date, passing as parameter to the database

Asked

Viewed 442 times

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.

Erro

  • I already handled the string error. But now it is processing, but it is not allowing the change. No errors.

  • You want to replicate the NULL correctly to the database, right? Which SQL is running?

  • @Ciganomorrisonmendez Correto. I am using SQL Server 2014

  • Okay, and what is SQL? Need to ask a question.

  • If you do a direct Insert in the bd works? You are using stored procedures to do the inserção/alteração?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.