Help !

  • Thread starter Thread starter Gary
  • Start date Start date
G

Gary

I have a function defined In a Class1.

Ex

Public Class1

Public Function GetData () as DataSet

******** Using SqlDatAdapter I fill the DataSet

******** It will return the Filled DataSet.

End Function

End Class



I have another Class which calls the GetData function of the first class.

Public Class2

Public Function UdateDatasetTODataBase()

Create Instance of the First class and Call the
GetData Function, which returns the DataSet.

'''''''' I want To Add/Update the Dataset and
reflect back to DataBase.. ****** How to Do this?????????????

End function

End Class



Using SqlDataAdapter this can be Done only if u fill the Dataset in the Same
Function, make Changes and Call the SqlDataAdapters Update method,

But I am filling the Dataset in Different function..

Is there anyway to assign already filled Dataset to SqlDataAdapter ?

TIA,

Gary
 
To reflect changes back, you could use following steps:
1. Create new SqlConnection
2. Create new SqlDataAdapter
3. Create new SqlCommandBulder using data adapter created on step 2
4. Open connection
5. Call SqlDataAdapter.Update(DataSet, table name) for each modified table
in the dataset
By default the SqlDataAdapter.Update method will use table named 'Table' for
update. You may also use the DataTableMapping for update customization.
6. Close connection

It's better to create separate class for data read/save purposes, and use
this class entire application
For example:

Public Class DataGateway
...
Publc Function GetData(query As String) As DataSet
...
End Function
Public Sub PutData(data As DataSet)
...
End Sub
...
End Class
 
Back
Top