Please help!!!!!!!!

  • Thread starter Thread starter nashak
  • Start date Start date
N

nashak

What is a preferred method to handle form input from textboxes that can
be empty or null (in C#). If I pass these values as parameters to a
method, then they fail when there is no data in the field.

I can check the value and if empty set it to System.DB.Null and then
create a sqlparameter[] and pass this to my method? In the method, I
can create my command, connection objects and use the SqlParameter[] to
add them to command.paramters.add.


VB Code:

Dim SQLParam() As SqlClient.SqlParameter
SQLParam = New SqlParameter() {New SqlParameter("@SubjectID",
SubjectID), New SqlParameter("@StudyID", StudyIID)}


What will the equivalent code be in C#?

Thanks
 
Yes, and no. If you want to take the server-side default value (and not
NULL) you'll need to set the SqlParameter.Value to null or Nothing in
VB--not DBNull.Value.


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
www.sqlreportingservices.net
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Hello RViray and Bill,

Thanks for your reply.

Bill mentioned no. I did not understand what exactly he meant.

I thought that I could write something like this:

if(SubjectID != "") {
SubjectID = Textbox1.text;
}

else {
SubjectID = DbNull.Value;
}

SQLParam = New SqlParameter() {New SqlParameter("@SubjectID",
SubjectID)};

This should handle null and empty fields.

Please let me know what you all think.
 
Back
Top