I'm playing with VB2010 express and MS SQLServer Express
I've made a small app that uses a Module function to retrieve a dataset then I mess around and change some values in the dataset. Now I want to update the database but all the examples I can find use the original dataadapter to do the update. My original dataadapter is gone so how do I do an update? I can't see any way to create a new datadapter without also creating a new dataset...
Pseudo code so you know what I mean (don't have program handy so don't sweat apparent mistakes in coding)
Any ideas? Or do I have to drop "Using" and make the adapter and dataset global?Code:Function DoQuery(ByRef myDataset as Dataset, myQuery as string) as boolean Dim result As Boolean = false myConnString = GetConnString() Using myConn as new SqlConnection(myConnString) myConn.Open() Using myAdapter as new SqlDataAdapter(myQuery,myConn) myConn.Close() myAdapter.Fill(myDataset) result = true End Using End Using return result End Function
Edit: Just realized... I should give the dataadapter the same scope as the dataset and pass both byref to the DoQuery.. I think. Hmmm, maybe I'll just do everything on each form since after the dataset and adapter there's not much more to doing the queries and I'm not saving a whole lot of coding by using a function in a module.




Reply With Quote
