.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 3rd, 2004, 01:31 PM
bigspike bigspike is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 1 bigspike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Updating a access database from a dataset

Hello,
I am not sure if this should be here or in one of the database treads but here is goes any way.

This application is a windows VB.NET form
I have two datasets. One from a web service that I call and one from a local access database. My problem is that I am not able to update the local database with the information from the web service dataset. And help would be great.

here is my code:

Dim d As New DataSet() ' dataset from web services

'For local access database
Dim oConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:\memberarea.mdb"
Dim oConn As New OleDb.OleDbConnection(oConnString)
Dim oDS As New DataSet()
Dim oAdapt As New OleDb.OleDbDataAdapter("Select firstname,lastname from staff", oConn)

Sub get_ds_web()
Dim o As New djwebminweb.sync()
d.Merge(o.getstaff("Select firstname,LastName from staff where acctnum='10001'"))
o = Nothing
End Sub

Sub get_ds_local()
oDS.Clear()
oAdapt.Fill(oDS, d.Tables(0).TableName)
oConn.Close()
End Sub

Private Sub updatelocalbd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updatelocalbd.Click
Cursor.Current = Cursors.WaitCursor

updatelocalbd.Enabled = False ' disable button once clicked

Call update_ds_local() ' update local database
Call get_ds_local() ' get new local dataset from db

' Fill New local db combobox
ComboBox3.DataSource = oDS.Tables("staff")
ComboBox3.DisplayMember = "firstname"

' Fill Merged dataset combobox
ComboBox4.DataSource = d.Tables("staff")
ComboBox4.DisplayMember = "firstname"

Cursor.Current = Cursors.Default
End Sub

Sub update_ds_local()
' set the olecommand select command
oAdapt.SelectCommand = New OleDb.OleDbCommand("Select firstname,LastName from staff", oConn)

' declare a ole command builder
Dim custCB As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(oAdapt)

'Open database
oConn.Open()

'merge the two record sets together
d.Merge(oDS)

'fill the ole dataadapter
oAdapt.Fill(d)

'update the dataset
oAdapt.Update(d, "staff")

'Close the db connection
oConn.Close()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Cursor.Current = Cursors.WaitCursor

Call get_ds_web() ' get remote dataset
Call get_ds_local() ' get local dataset

'Fill local db combbox
ComboBox1.DataSource = oDS.Tables("staff")
ComboBox1.DisplayMember = "firstname"

'Fill website db combbox
ComboBox2.DataSource = d.Tables("staff")
ComboBox2.DisplayMember = "firstname"

Cursor.Current = Cursors.Default
End Sub

Thank
Mike

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > Updating a access database from a dataset


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT