* Add Item to BoundSource ComboBox *

djreyrey

Member
Joined
Oct 14, 2009
Messages
6
Programming Experience
Beginner
Hello all!

Oh man oh man! :eek: This seems to be the toughest thing I've had to search for. It seems there's not a good thread that clearly explains how to add items to a combo box that's bound to a SQL Server table (of course, I'm a newbie so I'd like a step-by-step on how to get it done).

Can someone please help me out on how to get this accomplished? I really do appreciate any help I can get. :D
 
Add your new item directly to your bound source. For example if your combobox is bound to a datatable, then add a new record to your datatable.
 
Example?

Sir,

Do you have a sample code or sample project I can look at that demonstrates this? I'm newbie so I'm not sure how to begin.

Thanks for your assistance.:D
 
Add Data to ComboBox with Foreign Table

Please check out the attached PDF for a sample structure in Access. I need to replicate this in VB 2008. The form will attach to the table in SQL Server 2005. :confused:
 

Attachments

  • Screenshot.pdf
    208 KB · Views: 18
ComboBoxes aren't bound to SQL Server tables. You use ADO.NET to retrieve data from SQL Server into a DataTable. That DataTable may or may not be in a DataSet, but it doesn't really matter. It's the DataTable that you bind to the control, either directly or, preferably, via a BindingSource. You have two choices to add a new record:

1. Call NewRow on the DataTable to create a DataRow, populate the fields of that DataRow and then call Rows.Add on the DataTable to add the new row. If you are using a typed DataSet then the method names might be slightly different but the principle remains the same: create new, populate, add.

2. If you're using a BindingSource then you can use it to add the new record. Call AddNew to create a DataRowView, populate its fields and then call EndEdit on the BindingSource to commit the row to the underlying DataTable. It's the same principle as option 1 but the objects and methods are slightly different.
 
ComboBoxes

Sir,

Sounds great! But I'm a total newbie and I'm not sure exactly what code I need. Do you have sample code or a sample project that shows exactly how to do this?

Thank you very much. I really do appreciatei it.
 
Back
Top