how to pass sql parameter as null value in integer datatype variable?

TinTin picture TinTin · Jul 15, 2010 · Viewed 51k times · Source

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

Answer

ACP picture ACP · Jul 15, 2010

Try this,

else
    {
        sBO.Client_id = System.Data.SqlTypes.SqlInt32.Null;
    }