Please 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
 
Hi Gary,
You would need to either have a DataAdapter in your second class or expose
it as public on the first class but if you do you can update fine. One
thing that's not very apparent though is that you should do a Merge to get
the dataset into the second class otherwise you can end up with some
strange reference issues. The code would look something like this:

Public Class2
Public Function UdateDatasetTODataBase()
Dim c1 as New Class1

'get the dataset by merging it into a new dataset for
reference issues
Dim ds as new DataSet
ds.Merge(c1.GetData)

'do anything else you would like with the dataset

'update it with a new data adapter
DataAdapter.Update(ds)

'or update it with the public adapter on class1
c1.DataAdapter.Update(ds)
End function
End Class

Hope this helps,
Eric - VB.Net team
--------------------
| From: "Gary" <[email protected]>
| Subject: Please help !
| Date: Wed, 24 Sep 2003 18:25:03 +0530
|
| 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
|
|
|
 
Hi Gary,

I'm not sure, but you'd think there would be a way to do this - however, 2
points:

1. post this question to microsoft.public.dotnot.framework.adonet
2. why not build the dataset with the dataadapter in function getdata and
pass back the sqldataadapter as well as the dataset (pass by reference)?
Then they would be in sync.

HTH,

Bernie Yaeger
 
Back
Top