Getting Items Collection into Database

scuzzles

New member
Joined
Feb 15, 2006
Messages
2
Programming Experience
1-3
I have a form in vb.net with fields that are binded directly to the Access Database fields. User inputs and it goes into the database. Thats OK, but I have a Drop Down Combo Box with items listed from the Items Collection that is not getting into the database. How do I connect to get items from the drop down Combo box into the database field??
 

pooh

New member
Joined
Feb 16, 2006
Messages
3
Programming Experience
1-3
u can add the items to combo box with the value along with items. So that it will help in ceating linking between database table field. This can be done by adding item to combo box as listitem. The combo box item's value can be directly map to key feild of database table.
 

gopal2006

Well-known member
Joined
Feb 1, 2006
Messages
63
Programming Experience
1-3
You can insert the combobox name into database.

You can do like this



dtcmd.parameters.add("@table",oledbtype.varwchar,255,"fieldname").value = comboboxname.text

Use the above code as per your table and field names you have declared.
The first one is the parameter you are passing.Second on is the type of oledbtype value(if you r using sqladapter do it accordingly).Third one is is the size and the last one is the name of the field where you want to store the commbox name. Try this out
 

scuzzles

New member
Joined
Feb 15, 2006
Messages
2
Programming Experience
1-3
I need more help on this...I assume theres no way of using the GUI and the properties box to bind the combo box items to the database field?

Heres the auto generated/behind the scenes code for the combo box. I'm using "SelectedValue" here, but had "Text" in the 2nd line code but neither are working. Branch_Department is the database field I have to bind to.

Me.ComboBox1.BackColor = System.Drawing.SystemColors.ButtonFace
Me.ComboBox1.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.objdsCustDisp, "CustomerDispute.Branch_Department", True))
Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.ComboBox1.ItemHeight = 13
Me.ComboBox1.Items.AddRange(NewObject() {"1 Main Office", "2 Kensington", "3 South", "4 North", "5 City Line", "6 Boulevard", "7 Woodland Ave", "8 16th Street", "9 Lawrence Park", "11 Bell's Corner", "12 Academy Plaza", "13 Baltimore Pike", "14 Rosemore", "15 Folcroft", "16 Eddystone", "18 Springhouse", "19 Narberth", "20 Penn Center", "21 6th & Walnut", "22 Yeadon", "23 Ardmore", "24 Mayfair", "25 Bensalem", "27 Barderwood", "28 Drexel Hill", "29 Newtown", "30 Edgmont", "33 Whitemarsh", "35 Morrell Plaza", "36 Mt. Laurel", "37 Roxborough", "38 Exton", "39 Montgomeryville", "40 Holme Circle", "42 East Norriton", "43 Parkwood", "44 Aramingo", "45 Brous & Tyson", "100 TAP", "101 MAC", "102 Direct Deposit", "103 Mail Services", "104 Certificates", "105 EDP", "106 Lending Operations", "107 Pension", "108 Customer Contact", "109 Collections", "110 Consumer Credit"})
Me.ComboBox1.Location = New System.Drawing.Point(96, 264)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(136, 21)
Me.ComboBox1.TabIndex = 8
 

pooh

New member
Joined
Feb 16, 2006
Messages
3
Programming Experience
1-3
hello
I am not getting what exactly u want to do. The way u r storing values in that u wont be able to retreive selectedvalue. In this case u have to take selecteditem.text.
 

scuzzles

New member
Joined
Feb 15, 2006
Messages
2
Programming Experience
1-3
Help

I'm lost. This seems like such an easy thing. In the Visual Studio Software, I entered items into the collections for a drop down combo box(very simple, 1 per each line) and the code I listed above is the auto-generated code that Visual Studio made. I havent created any code.
I simply need the selection in the combo box to reach my database field "Branch_Department". All the other fields on the form are binded to the correct database field via Data Bindings / Text....

for example:
objdsCustDisp - CustomerDispute.Customer
objdsCustDisp - CustomerDispute.Address
 
Top Bottom