c# - Is it possible to Pass Empty Parameter to sql server from code behind? -


I have some parameters in the SQL query that only accept the 'value' which does not consider it blank, 'How is this value as a parameter, my code below which I am trying to do?

  param = new SqlParameter ("@ CodeNumber", SqlDbType.VarChar); If (! String.IsNullOrEmpty (SearchCriteria.CodeNumber)) {param.Value = SearchCriteria.CodeNumber; } And {param.Value = DBNull.Value; //param.Value = ''; I want to do something like this} CMD. Parameter. Add (Ultimate); Ultimate = new escappamator ("@ Licensed", SqlDbType.DateTime); If (Search Certification .License Date! = Null & amp; Search Calculator. License Date! = Default (Datetime)) {param.Value = SearchCriteria.LicenseDate; } And {param.Value = DBNull.Value; //param.Value = ''; I want to do something like this} CMD. Parameter. Add (Ultimate);   

I have not received any error but in the query it is not taking it as ''

empty string as a parameter when the underlying field is varchar :

  param = New SQLparator ("codenumber", SQLDB type worker); If (! String.IsNullOrEmpty (SearchCriteria.CodeNumber)) {param.Value = SearchCriteria.CodeNumber; } And {param.Value = String.Empty; } cmd.Parameters.Add (param);   

For the date format , the SQL server will treat the empty string in a DateTime column 1/1 / 1 9 00 12:00:00 AM, as seen. Therefore, instead of the empty string, you can pass in the code like this in DateTime , such as:

  param = new SqlParameter ("@ LicenseDate") SqlDbType. Date Time); If (Search Certification .License Date! = Null & amp; Search Calculator. License Date! = Default (Datetime)) {param.Value = SearchCriteria.LicenseDate; } And {param.Value = new date time (1900,1,1,0,0,0)} cmd.Parameters.Add (param);    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -