Save method

johmolan

Well-known member
Joined
Oct 11, 2008
Messages
129
Programming Experience
Beginner
I use the binding navigatorsaveitem to save my data back to the database, but the way I am doing it today seems to take an awful lot of time.
Ex:
VB.NET:
Private sub .....SaveItem_Click(Etc Etc Etc)Handles ....Click

Me.Validate()
Me.Process1BindingSource.EndEdit()
Me.Process2BindingSource.EndEdit()
Me.Process3BindingSource.EndEdit()
Me.Process4BindingSource.EndEdit()
Me.Process5BindingSource.EndEdit()
Me.Process6BindingSource.EndEdit()
Me.Process7BindingSource.EndEdit()
Me.Process8BindingSource.EndEdit()
Me.Process9BindingSource.EndEdit()
Me.Process10BindingSource.EndEdit()
Me.Process11BindingSource.EndEdit()

Me.TableadapterManager.UpdateAll(Me.DataSet)

'Then I run a Methot who runs all my processes to calculate the new values.
Kjor()

'Ten I save all the new calculated values back to the database again.

Me.Validate()
Me.Process1BindingSource.EndEdit()
Me.Process2BindingSource.EndEdit()
Me.Process3BindingSource.EndEdit()
Me.Process4BindingSource.EndEdit()
Me.Process5BindingSource.EndEdit()
Me.Process6BindingSource.EndEdit()
Me.Process7BindingSource.EndEdit()
Me.Process8BindingSource.EndEdit()
Me.Process9BindingSource.EndEdit()
Me.Process10BindingSource.EndEdit()
Me.Process11BindingSource.EndEdit()

Me.TableadapterManager.UpdateAll(Me.DataSet)

Is there any "easier" or faster way to do this.?
I use datagridview to display the numbers and I do the changes in the datagridview.
Of cource I could have 1 buton on each tab to save each datagridview but I think that is not how I would like program to be if I was to use it.
 
Since No one have any idea on this one I will try another angle.

Is there a way to determine if the datagridview har been altered?

The dataset.haschanges will not work since it includes the whole dataset.
I need to be able to check if one of the tables has been changed and not the whole database.
 
-how about this?

I am trying to make a method where I can choose which prosesses to save,

VB.NET:
Private Sub Save(ByVal prosess As String)
     
        For Each row As DataRow In Me.Kalkyle1DataSet.Tables("prosess")
            If row.RowState = DataRowState.Added Or DataRowState.Modified Or DataRowState.Deleted Then
                Me.Stalsoyler_totalTableAdapter.Update(stalstupdates)
            End If
        Next





    End Sub

But I get an error saying :


Error 1 Expression is of type 'System.Data.DataTable', which is not a collection

Can anyone help me out here?
 
there is a method for checking if table data has change. Just can't seem to remember it now. Look at the properties and methods of the table using the intellisense dropdown, im sure its easy to spot.
i also don't think there is a need to check if there are any rows added, deleted, etc. Because the update statement only saves data that has changed.
 
oh now i remember i usually use the expression:
VB.NET:
If table.GetChanges() Is Nothing Then
    'there are no changes
End If
 
Back
Top