473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Don't know how to handle C# null values in form controls!!

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?
Oct 1 '07 #1
9 2411
Frinavale
9,735 Expert Mod 8TB
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?
How 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
Oct 1 '07 #2
How 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?
Oct 2 '07 #3
Frinavale
9,735 Expert Mod 8TB
That's going to be a lot of extra code. Is there a simpler way to do it? Or no?
No... sorry.

-Frinny
Oct 2 '07 #4
Shashi Sadasivan
1,435 Expert 1GB
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.IsMyFieldName_Null() == true

seems like abt 4 lines of code to me....(2 lines for each bracket)

cheers
Oct 2 '07 #5
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.IsMyFieldName_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?
Oct 3 '07 #6
Shashi Sadasivan
1,435 Expert 1GB
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

cheers
Oct 3 '07 #7
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

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.
Oct 3 '07 #8
Shashi Sadasivan
1,435 Expert 1GB
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.

cheers
Oct 3 '07 #9
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.

cheers

Awesome. Thanks so much for your help!!!!!!!!!
Oct 3 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: John Smith | last post by:
Hello all: Does anyone happen to know the best way to handle null values for DateTimePickers? We have quite a few columns in our db that will not necissarily have a date for certain entries. ...
1
by: DKode | last post by:
I find myself writing repetitive functions for handling null values from my DB like so: Private Function SetDateNull(ByVal p_date As Object) As Date If (TypeOf (p_date) Is System.DBNull) Then...
10
by: Rob Meade | last post by:
Hi all, I've got myself into a bit of a problem and I'm trying to dig my way back out, in a) the quickest way due to project deadline and also b) best approach. I have a form which gets a set...
11
by: eddy de boer | last post by:
Hello, in my aspx page I have the followong code: <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> .... <%# Server.HtmlDecode((string)DataBinder.Eval(Container.DataItem,"tekst"))...
0
by: Jason Coyne | last post by:
Here is another programming blog entry. Sorry for the normal friends :) I recently ran into a problem with a web service I was trying to call from c# where the web service returned null dates...
3
by: psycho | last post by:
how should i hanle null values returned by the datareader i am using OleDbDataReader for accessing access database.
2
by: jehugaleahsa | last post by:
Hello: Is there a way to handle null values for ints, DateTime, etc. in generated DataTables? It seems it is not something the Microsoft crew thought of. That is hard for me to believe. ...
5
by: tonialbrown | last post by:
I have some code that updates a record's fields based on a selection from a list box (lstDelFrom). The user selects the record from the list box & it copies it into the fields , , etc. My...
1
by: apache626 | last post by:
I really need help with this one. I am using a script task to write data pulled from a MS SQL DB to a fixed width file. The script takes the ItemArray and writes the value of the column to the file...
1
by: NareshN | last post by:
Hi, I am using this stored procedure with pivot.If i dont have data i am getting null with this stored procedure.Can u tell me how to handle null.below query is pivot. I am using like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.