I'm developing a C# application in Visual Studio that have forms which insert values into an sql database. I am allowing null values in the database. However, I have some combo boxes on the forms that give me an error when I insert the form values into the database. It allows me to have null values in the textboxes, but not the combo boxes. How can I fix this problem?
Don't know how to handle C# null values in form controls!!
Collapse
X
-
Tags: None
-
Originally posted by jakeesgirlI'm developing a C# application in Visual Studio that have forms which insert values into an sql database. I am allowing null values in the database. However, I have some combo boxes on the forms that give me an error when I insert the form values into the database. It allows me to have null values in the textboxes, but not the combo boxes. How can I fix this problem?
If you are looping through your DataSet to do so, you should check if the value is null...if it is, don't add it.
-Frinny -
Originally posted by FrinavaleHow are you filling your combo boxes?
If you are looping through your DataSet to do so, you should check if the value is null...if it is, don't add it.
-Frinny
That's going to be a lot of extra code. Is there a simpler way to do it? Or no?Comment
-
since its a combo box , i presume you would only be assigning the items from one specific field of your retrieved table.
Check the row.IsMyFieldNa me_Null() == true
seems like abt 4 lines of code to me....(2 lines for each bracket)
cheersComment
-
Originally posted by Shashi Sadasivansince its a combo box , i presume you would only be assigning the items from one specific field of your retrieved table.
Check the row.IsMyFieldNa me_Null() == true
seems like abt 4 lines of code to me....(2 lines for each bracket)
cheers
My problem is, I have about 8 combo boxes on this form, and I would have to re-write a new sql insert statement for each possibility of nulls in the combo boxes. For example, if I have 3 combo boxes (box1, box2, box3), I would have these possibilities of insert statements:
insert into table (column1, column2, column3) values (box1, box2, box3)
insert into table (column1, column2) values (box1, box2)
insert into table (column1) values (box1)
insert into table (column2) values (box2)
insert into table (column3) values (box3)
insert into table (column2, column3) values (box2, box3)
insert into table (column1, column3) values (box1, box3)
With about 8 combo boxes, that adds up to a lot of insert statements. Is there any better way to do this?Comment
-
Sorry for that.
I thought you were quering about how not to allow Null values from being populated in a combo box.
for this case, if you get a field value as null (Which has to inserted into your combo box) insert a space or empty text field into your combobox.
and this way you can get one insert statement to do the job for you
cheersComment
-
Originally posted by Shashi SadasivanSorry for that.
I thought you were quering about how not to allow Null values from being populated in a combo box.
for this case, if you get a field value as null (Which has to inserted into your combo box) insert a space or empty text field into your combobox.
and this way you can get one insert statement to do the job for you
cheers
With this same form, I want the user to be able to search the database. How would I handle select statements in this case? They have all the combo boxes available, but they just enter in the information they have. So the select statement is going to depend on which combo boxes they make a selection. What is the best way to write my code? The way I'm imagining the code right now is really long and tedious.Comment
-
If you can dynamically create your SQL statements then for each text/combo box whose text.Length > 0 , you can add its fields to the SQL statement using the "AND" operator.
cheersComment
-
Originally posted by Shashi SadasivanIf you can dynamically create your SQL statements then for each text/combo box whose text.Length > 0 , you can add its fields to the SQL statement using the "AND" operator.
cheers
Awesome. Thanks so much for your help!!!!!!!!!Comment
Comment