how to pass sql parameter as null value in to integer data type variable ?
StockBO sBO = new StockBO();
sBO.Mode = 2;
if (ddcmpanyname.SelectedIndex != 0)
{
sBO.Client_id = Convert.ToInt16(ddcmpanyname.SelectedValue);
}
else
{
sBO.Client_id = Convert.ToInt16(DBNull.Value);//Object cannot be cast from DBNull to other types.
sBO.Client_id =DBNull.Value;//Cannot implicitly convert type
}
ds=_StockController.StockGet(sBO);
i changed the code like this it gives error like i my comment check else part
SQL also has NULL which means "Unknown". A NULL value can be set. NULL is a non-value, so it can be assigned to TEXT columns, INTEGER columns or any other datatype.
How To Assign NULL Values to Variables or Columns? The rule for assigning NULL values to variables or table columns is simple: Use keyword "NULL" directly as normal values. Specificly, "NULL" can be used in SET statements to assign NULL values to variables.
You can't pass a primitive as null. There's two ways to do this- first is to make the function take Double- the class version of a double. The other is to pass in some unused value, such as -1, to mean null. That requires there to be a reasonable default value though.
ALTER TABLE table_name ALTER COLUMN column_name DATA_TYPE [(COLUMN_SIZE)] NULL; In this syntax: First, specify the name of the table from which you want to change the column. Second, specify the column name with size which you want to change to allow NULL and then write NULL statement .
Try this,
else
{
sBO.Client_id = System.Data.SqlTypes.SqlInt32.Null;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With