This is a migrated thread and some comments may be shown as answers.

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

1 Answer 35 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 2
Adam asked on 21 Feb 2012, 09:59 PM
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 

1 Answer, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 23 Feb 2012, 08:12 PM
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);
}
Tags
Grid
Asked by
Adam
Top achievements
Rank 2
Answers by
Elliott
Top achievements
Rank 2
Share this question
or