Results 1 to 5 of 5

Thread: Update from Dataset without original adaptor?

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2012
    Posts
    136

    Question Update from Dataset without original adaptor?

    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)

    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
    Any ideas? Or do I have to drop "Using" and make the adapter and dataset global?

    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.
    Last edited by pmeloy; May 31st, 2014 at 12:37 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width