.net sql insert statement - how to avoid null values

I have an insert statement in my aspx.cs file.  I'm trying to avoid having a Null value in my record.  Not sure the best way to handle this when the user does not provide data in this text box?
I'm currently  just adding a space to every entry.  (I would prefer a space over "N/A".)
command.Parameters.Add("@MiddleName", SqlDbType.VarChar, 50).Value = 
TextBoxMiddleName.Text.Trim() + " ";

Open in new window

Thanks.
javierpdxAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Surendra NathConnect With a Mentor Technology LeadCommented:
This should do

command.Parameters.Add("@MiddleName", SqlDbType.VarChar, 50).Value =
TextBoxMiddleName.Text.Trim().Length == 0 ? "N/A" :  TextBoxMiddleName.Text.Trim();
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Another way would be to add a required field validator to the front end forcing the user to fill in something before submitting it to the db.
0
 
javierpdxAuthor Commented:
This is a cleaner solution than what I would have used.  I appreciate it.
0
All Courses

From novice to tech pro — start learning today.