Question : add/edit/delete from dataset, and bind a field in dataset to a combobox,

good day, the problem im having is that i need to fill textboxes according to the value the user clicks in a combobox.
the combobox is filled via a dataset.
from there i need to add edit and delete customers.
vb.net & access 2000,oledb
e.g.

combobox: (user chooses)         '1'

(then according to the userid)

textbox1:                        'Gary'
textbox2:                        'Johnson'

THE DATA SIDE
-------------
i have a table called customers
the customers table has the fields
CustomerID (autonumber)
Name       (text)
Surname    (text)

now i have a strongly typed dataadapter 'daCustomers' which only uses the customers field
the insert,delete & update commands are all working fine.
now i have a dataset which was generated by the daCustomers dataadapter.
if i preview the dataAdapter's fill dataset, i get the results fine, no problem

THE FORM SIDE
-------------
combobox1
textbox1  
textbox2
btnAdd
btnEdit
btnDelete

now the whole plan here is to be able to ADD, EDIT & DELETE customers.

this is what i got and now im stuck
i have 3 similar situations in this specific application and i would like to do this the right way so i can apply it in
all my future vb.net projects.
the specific situations are SUPPLIERS, CUSTOMERS, MANUFACTURERS in this project. so the user will click on a
TooLBAR button to select customers now.

i can honestly go screw around and eventually get it right but i cant afford it right now
so what im asking is either:

a link to a similar sample,  
OR
a step by step walkthrough, not neccessarily code, just the steps.
i will post my code if it is requested.

some of my immediate questions in my quest to finish this project
----------------------------------------------------------------
when do i bind the datasource of the combobox to the dataset?
do i do it at designtime by selecting the properties or do i do it in code when the user presses the CUSTOMERS toolbar

button?
i just set the combobox's datasource to dsCustomers.customers
and the display member to customerID, but when i run the program, and select customers, the combobox is empty


then what do i do in the click event of the combobox?
what event do i use for the combobox to now call the code that fills the textboxes?
how do i tell the textboxes to fill up with the values according to the ID in the combobox?

am i doing it right so far or would it be better to not have everything strongly typed?

would datareaders be brought in at any stage?

once again, im asking a whole bunch.
thank you!

Answer : add/edit/delete from dataset, and bind a field in dataset to a combobox,

You will need to set the combobox data source when the user selects the relevent toolbar button:

'Create a DataView
Private dv as dataview

Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick

     Select case e.Button.Text
          Case "Customers"

            Me.ComboBox1.DataSource = oDs.Tables("Customers")
            Me.ComboBox1.DisplayMember = "CustomerID"
            Me.dv = new DataView(oDs.Tables("Customers"))

          Case "Suppliers"

            Me.ComboBox1.DataSource = oDs.Tables("Suppliers")
            Me.ComboBox1.DisplayMember = "SupplierID"
            Me.dv = new DataView(oDs.Tables("Suppliers"))

          ... and so on

       End Select

End Sub

Then you will need to respond to the selected index changed for the combo box to set the values in the text boxes:

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

        Me.dv.rowfilter = Me.dv.Table.Columns(0).ColumnName & "=" & Me.Combobox1.SelectedText
        Me.TextBox1.Text = dv.Item(0)(1).ToString
        Me.TextBox2.Text = dv.Item(0)(2).ToString

End Sub

For each of the buttons you will have to add the relevent code to respond to the required action, so:

Add:
Get the values of in the textbox and create a new row in the dataview

Edit
Update the row in the dataview with the details in the textboxes

Delete
Set the row in the dataview as to be deleted.

It is up to you then whether you run the Update method of the dataadapter after each action, or when the user specifies it.

Hope this helps.

Tom
Random Solutions  
 
programming4us programming4us