Check on Combo Boxes for Database Insert

retkehing

Well-known member
Joined
Feb 5, 2006
Messages
153
Programming Experience
Beginner
I have thirty something combo boxes in one of my form, and i have set all of these combo boxes default text to "Please select". This form allows user to perform database transaction like save, delete, update and search function.

My problem is that when the user wants to perform add transaction without selecting the proper option of combo box, it will insert the "Please select" into the database and actually it is a null value, the field should be empty for non selected combo box.

I dont want to hardcode it and set all these combo boxes.text to "" so i tried to create an string array which it is used to store all these combo boxes name and then i called a function to execute the check. I managed to pass the string array to the function and however the function cannot recognize the type of member of array, for example, i coded like this

if a(0).text="Please select" then
return a(0).text=""

I know this definitely won't work but i have no idea how my concept can be done. Anyone can help on this? Thank you.
 
But in order to do that, i must need to repeat the following code for thirty times:
if Combox1.selectedindex=0 then
Combox1.selectedindex=""

Is there any way to make the code more maintainable apart from hardcoding it? For example call function and may i know how that can be done in function? Thank you.
 
May be play with this kind of code?

VB.NET:
Expand Collapse Copy
        Dim obj As Object
        For Each obj In Me.Controls
            If TypeOf (obj) Is ComboBox Then
                If DirectCast(obj, ComboBox).SelectedIndex <= 0 Then
                    MessageBox.Show("You haven't select item in " & DirectCast(obj, ComboBox).Name)
                End If
            End If
        Next
 
Back
Top