Question updating through dgv

jamie123

Well-known member
Joined
May 30, 2008
Messages
82
Programming Experience
Beginner
Hi, I'm programming in vb.net using vs2008 and sql2005.

Here is my issue, I have the following code:

VB.NET:
     If e.ColumnIndex = 0 Then
            param = InputBox("Edit frame name?", "Edit")
            id = e.ColumnIndex + 1
            Me.MaterialsTableAdapter.EditFrame(param, id)
            Me.MaterialsTableAdapter.fill(Me.Dataset.Materials)
            Me.MaterialsTableAdapter.Update(Me.DataSet.Materials)

This occurs when a datagridview column is clicked, if the column happens to be 0, it does that routine (edits the row/column) Here is the code that is contained in the "editframe" sql query:

VB.NET:
UPDATE [dbo].[Materials] SET [Frame] = @Frame WHERE (ID = @ID)


MY PROBLEM:

After updating this code, and refilling the dataset, my dgv should reflect the changes, yes?

It doesn't though, and I feel as if its not a matter of the datagridview not being updated, if I insert new data into the dgv using insert statements, the change is reflected in the dgv and the dgv is refreshed using the same code which i showed above. I don't think something is updating right, but I've always updated info in sql servers using the above type method, why is this not working correctly?

Thanks !
 
I'm 99% sure it's the same dataset, I configured everything within VS2008 graphically, set the datasource of the datagrid to my dataset, and programmatically called the exact same dataset, i don't see how there could be different datasets. I never dim another dataset.
 
On the bindingsource that the datagridview binds through to get to your table, call ResetBindings(false)

dgv->bindingsource->datatable
datatable.addxxxrow(blah)
bindingsource.resetbindings(false)


you can also set the default values of all the columns in the datatable to be ones you wish to have, and then call BindingSource.AddNew

datatable.NameColumn.DefaultValue = "John"
datatable.AgeColumn.DefaultValue = 23
BindingSource.AddNew()
 
cjard: I really do not know what I am doing wrong, I have tried both of your methods (unless I'm doing something wrong, which is defintely possible) but neither of them are working for me...granted, they work for the dgv, but I tried the same method for a combobox that is having the same issue (data inserted, combobox datasource won't reset until form is reloaded). With both of your methods I tried, even when closing the parent form and then reopening it, the combobox is not updated. Possibly an error in my datatable.addrow syntax? Here's what I tried for both of your methods

VB.NET:
         DataSet.Labs.Lab_NameColumn.DefaultValue = txtName.Text
            DataSet.Labs.AddressColumn.DefaultValue = txtAddress.Text
            DataSet.Labs.CityColumn.DefaultValue = txtCity.Text
            DataSet.Labs.StateColumn.DefaultValue = txtState.Text
            DataSet.Labs.Zip_CodeColumn.DefaultValue = txtZip.Text
            DataSet.Labs.PhoneColumn.DefaultValue = txtPhone.Text
            DataSet.Labs.FaxColumn.DefaultValue = txtFax.Text

            LabsBindingSource.AddNew()
VB.NET:
           Dim row As DataRow
            row = Me.DataSet.Labs.NewRow
            row("Lab Name") = txtName.Text.Trim
            row("Address") = txtAddress.Text.Trim
            row("City") = txtCity.Text.Trim
            row("State") = txtState.Text.Trim
            row("Zip Code") = txtZip.Text.Trim
            row("Phone") = txtPhone.Text.Trim
            row("Fax") = txtFax.Text.Trim
            DataSet.Labs.AddLabsRow(row)
            LabsBindingSource.ResetBindings(False)

So again, the dgv is now working fine, thank you everyone for your help.

However, I am having the same issue with a combobox, and the above code is not working with it in the same way.

Side note: Should I be using direct-db insertion methods for the combobox? Or since it is a databound control should I be inserting into the datatable?

Thanks!
 
Back
Top