locked
Converting Empty String to DBNull type RRS feed

  • Question

  • User-341994687 posted

    Hi,

    I am trying to convert an empty string, int etc to a null type in the database. I have a seperate data access layer. So in the class in the insert I have the following.

    SqlParameter

    paramADVehMake = new SqlParameter("@AD_Veh_Make", SqlDbType.VarChar, 10);

     

    if ( ad.getVehicleMake() == null || ad.getVehicleMake == "")

    {

    paramADVehMake.Value = System.

    DBNull.Value;

    }

     

    else

    {

    paramADVehMake.Value = ad.getVehicleMake();

    }

    But I am getting an error for the DBNull. Can anyone show me where I am going wrong.

    Thanks in advance,

        Seamus McMahon

    Tuesday, April 19, 2011 9:36 AM

Answers

  • User-1313990200 posted

    What is the error you are getting?If possible post the table structure.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 19, 2011 9:41 AM

All replies

  • User-1313990200 posted

    What is the error you are getting?If possible post the table structure.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 19, 2011 9:41 AM
  • User-341994687 posted

    Hi,

     

    Sorry. This was an easy one. Just realised I have not added the .value  to the paramValue on the left hand side.

     

    Thanks for the help anyway.

    Tuesday, April 19, 2011 9:45 AM