Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

insert null in datetime field when datepicker value havent chosen

$
0
0

hi,
I can insert a date time value that user choose from datepicker in table like below


5/2/2010

but i want to insert null if date hasn't been chosen.
so I write this code

DBase.ExecuteNoneQuery(System.Data.CommandType.Text, sql, new OleDbParameter[]{
              new OleDbParameter("@child_age", JQDatePicker1.Date !=null ? JQDatePicker1.Date :  DBNull.Value )



but it face with below error:
Type of conditional expression cannot be determined because there is no implicit conversion between 'System.DateTime?' and 'System.DBNull'

and when I convert dbnull.value like this

Convert.ToDateTime( DBNull.Value)

it throws below error

Object cannot be cast from DBNull to other types.

but I tried this one

new OleDbParameter("@child_age", DBNull.Value )

and it insert null in tableInnocent

what's the solution?

one other thing I work with microsoft access not sql server

thanks a lot


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>