tags:

views:

44

answers:

2

Hi

If i didn't place any date in the textbox ,system is capturing 1/1/1900 by default insted of Null.How can i get rid of this.

cmd.CommandText = "Update FormMaster set BriefingDate ='" + TextBox7.Text + "'

where FormID =" & Val(AutoID.Text)

cmd.ExecuteNonQuery()

Thank You

+1  A: 

i would recomend that you specifically check the value of TextBox7 before and assign to a var, so if the date is correct assign the value "'" + TextBox7.Text + "'" else just assign NULL.

this would lead to statement being UPDATE TABLE SET DATE = NULL if required OR UPDATE TABLE SET DATE = 'DATE' otherwise

astander
+2  A: 

1) Please use the cmd.Parameters collection to set SQL parameter values.

2) Write a function ToDBNullableDate(string) which converts a string into a DateTime and an empty string to DBNull

object ToDBNullableDate(string s)
{
    if (string.IsNullOrEmpty(s))
        return DBNull.Value
    return Convert.ToDateTime(s);
}
devio