updating database using dataset
-
Hey guys, This is some information which I have been reading on many websites regarding datasets. A dataset is the local repository of the data used to store the tables and disconnected record set. When using disconnected architecture, all the updates are made locally to dataset and then the updates are performed to the database as a batch. Please refer to the words that I have marked as bold. Can anyone tell me how that is done. I am a fresher in .NET. I really think that the execution speed of my application suffers since I update each record individually. I want to know how I can add/modify/delete to a dataset and then update the changes to the database. With Best Regards, Mayur
-
Hey guys, This is some information which I have been reading on many websites regarding datasets. A dataset is the local repository of the data used to store the tables and disconnected record set. When using disconnected architecture, all the updates are made locally to dataset and then the updates are performed to the database as a batch. Please refer to the words that I have marked as bold. Can anyone tell me how that is done. I am a fresher in .NET. I really think that the execution speed of my application suffers since I update each record individually. I want to know how I can add/modify/delete to a dataset and then update the changes to the database. With Best Regards, Mayur
Here are two funtions for Access.
Private Sub Do_Some_Work() Dim dt as DataTable FillTable(dt,"SELECT * FROM TableName") ' 'Modify the table ' UpdateTable(dt,"SELECT * FROM TableName") End Sub Public Function FillTable(ByRef dt As DataTable, ByVal SelectString As String) As Boolean Dim path As String = Application.StartupPath Dim cnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _ & " Data source= " & path & "\MyDB.mdb" Dim strSelect As String = SelectString '& ";Connect Timeout=10" Dim cn As New OleDb.OleDbConnection(cnStr) Dim cmd As New OleDb.OleDbCommand(strSelect, cn) Dim da As New OleDb.OleDbDataAdapter(cmd) cmd.CommandTimeout = 5 Try da.FillSchema(dt, SchemaType.Source) da.Fill(dt) Return True Catch ex As Exception Messagebox.Show(ex.Message) Return False Finally cn.Close() End Try End Function Public Function UpdateTable(ByVal dt As DataTable, ByVal strSelect As String) As Boolean Dim path As String = Application.StartupPath Dim cnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _ & " Data source= " & path & "\MyDB.mdb" '& ";Connect Timeout=10" Dim cn As New OleDb.OleDbConnection(cnStr) Dim cmd As New OleDb.OleDbCommand(strSelect, cn) Dim da As New OleDb.OleDbDataAdapter(cmd) Dim cb As New OleDb.OleDbCommandBuilder(da) cmd.CommandTimeout = 5 Try cb.GetUpdateCommand() da.Update(dt) Return True Catch ex As Exception Messagebox.Show(ex.Message) Return False Finally cn.Close() End Try End Function
-
Hey guys, This is some information which I have been reading on many websites regarding datasets. A dataset is the local repository of the data used to store the tables and disconnected record set. When using disconnected architecture, all the updates are made locally to dataset and then the updates are performed to the database as a batch. Please refer to the words that I have marked as bold. Can anyone tell me how that is done. I am a fresher in .NET. I really think that the execution speed of my application suffers since I update each record individually. I want to know how I can add/modify/delete to a dataset and then update the changes to the database. With Best Regards, Mayur
When you use a DataSet, or DataTable, with a DataAdapter object, you supply the DataAdapter with the SELECT statement to fill the DataSet. Your user makes any required changes to the data, then tells your app to update the database. This is where I think you're duplicating the functionality of the DataAdapter. The DataAdapter also needs the appropriate SQL commands for UPDATE, INSERT, and DELETE operations on the data it retrieved using the SELECT command. When the dirty data is written back to the database, the DataAdapter looks at each recond in the DataSet/DataTable and, using a flag attached to each record, decides which of those SQL commands to execute for that record, if any. You may be doing the same thing, or something similar. But, in any case, you're probably duplicating the functionality of the DataAdapter. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome