c# - How to pass a NULL value to Stored Procedure -



c# - How to pass a NULL value to Stored Procedure -

i passing datetime param stored procedire inserts value along other valus in table.

the code utilize passing variable

cmdproc.parameters.addwithvalue("@pi_tdc_datetime_stamp", convert.todatetime(param[7]));

now array 'param gets value tsv file , in of rows of file datetime blank ok. need pass null variable. code fails hits such entry , exception throws up.

string not recognized valid datetime. @ system.datetime.parse(string s, iformatprovider provider) @ system.convert.todatetime(string value)

i know sure code , stored procedure insert values works because inserts 10 values , breaks when hits empty datetime column. how can overcome issue

use datetime.tryparse check if there valid date, otherwise pass dbnull.value

datetime dt; if (datetime.tryparse(param[7], out dt)) { cmdproc.parameters.addwithvalue("@pi_tdc_datetime_stamp", dt); } else { cmdproc.parameters.addwithvalue("@pi_tdc_datetime_stamp", dbnull.value); }

c# sql datetime null

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

ruby on rails - Devise Logout Error in RoR -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -