Finding values of all controls in edit form to prevent null issue in SQL Database

2 posts, 0 answers
  1. Adam
    Adam avatar
    1 posts
    Member since:
    Dec 2011

    Posted 21 Feb 2012 Link to this post

    I have a simple radgrid that is attached to a SQL database table whose scheme I am not able to alter. There are a number of fields that do not allow NULLS in the database but for my purposes I can allow NULLS for certain fields.
    My question is, what is the best way to handle this? there are probably a dozen fields in this grid and the majority are simply text boxes. My first thought was that when the update command is fired to loop through all of the controls to check if they are NULL and if they are to simply make them pass a space. My problem is I am not sure how to do this easily. 
    Can anyone think of a better way to do this? 
    Thank you 
    Adam 

  2. Elliott
    Elliott avatar
    391 posts
    Member since:
    May 2010

    Posted 23 Feb 2012 Link to this post

    well, if you update in code you can send your parameters through one or more functions to set a NULL to some default value or values

    public void UpdateDB(object param1,object param2)
     
    SQLParameter param1 = new SQLParameter("@param1",SQLDbType.VARCHAR,10);
    param1.Value = SetDefault(param1);
     
    private string SetDefault(object param)
    {
      if (param == DBnull.Value)
      return string.empty;
    else
      return Convert.ToString(param);
    }

Back to Top