Updating a record in an MS Access database file using DataSets

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2007
Posts: 4
Reputation: Oblivi8or is an unknown quantity at this point 
Solved Threads: 0
Oblivi8or's Avatar
Oblivi8or Oblivi8or is offline Offline
Newbie Poster

Updating a record in an MS Access database file using DataSets

 
1
  #1
Jun 30th, 2007
Hi.

I'm fairly new to VB.NET programming, and i'm currently developing an application for the sake of experience.

What i know about Visual Basic programming might be considered dangerous, but none the less, i'm trying.

I'm having difficulty getting past the idea of how to update a record in a Microsoft Access 2000 database file. I have no problems inserting, deleting and creating new records in the database, but somehow it seems that there's more to updating a record than what i had expected.

The following code is what i use to collect the data of a specific row in my mdb file, and then displaying the data in the corresponding textbox which i have on my windows form.

  1. Dim con As New OleDb.OleDbConnection
  2. Dim ds As New DataSet
  3. Dim da As OleDb.OleDbDataAdapter
  4. Dim sql As String
  5.  
  6.  
  7. con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\bin\MY_DATABASE.mdb"
  8. con.Open()
  9.  
  10. sql = "SELECT * FROM client WHERE ID = 1"
  11. da = New OleDb.OleDbDataAdapter(sql, con)
  12. da.Fill(ds, "ClientList")
  13.  
  14. con.Close()
  15. 'filling the corresponding textbox named txtName which I have on my windows form
  16. txtName.Text = ds.Tables("ClientList").Rows(0).Item("Name")

I managed to get past that and work myself around in order to fill the respective text boxes on my windows form.

Now the problem i'm facing, is that i have 3 buttons on this form, which should enable me to ADD, DELETE, or UPDATE the record by filling in or editing the text boxes on the form.

So many times have I tried, and so many times have i searched accross the Internet, and I cant seem to resolve this problem.

I want the update method to work like that of the code snippet I provided above, or atleast something similar to that.

Could anyone please help me with this?

Thank you in advance. Really appreciate it.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 8
Reputation: vamas is an unknown quantity at this point 
Solved Threads: 1
vamas vamas is offline Offline
Newbie Poster

Re: Updating a record in an MS Access database file using DataSets

 
0
  #2
Jun 30th, 2007
to update Database (vb.net Code)

Dim cb as new oledb.oledbcommandbuilder(da)
ds.tables("yourtablename").rows(rowno).item(columnno)="Value"
ds.tables("yourtablename").rows(rowno).item(columnno)="value"
da.update(ds, "Yourtablename")



'da = dataadapter object
'ds = dataset object
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 4
Reputation: Oblivi8or is an unknown quantity at this point 
Solved Threads: 0
Oblivi8or's Avatar
Oblivi8or Oblivi8or is offline Offline
Newbie Poster

Re: Updating a record in an MS Access database file using DataSets

 
0
  #3
Jun 30th, 2007
Originally Posted by vamas View Post
to update Database (vb.net Code)

Dim cb as new oledb.oledbcommandbuilder(da)
ds.tables("yourtablename").rows(rowno).item(columnno)="Value"
ds.tables("yourtablename").rows(rowno).item(columnno)="value"
da.update(ds, "Yourtablename")



'da = dataadapter object
'ds = dataset object
Thank you Vamas.

I tried your code, but i keep getting a Microsoft Error report whenever I click the Update button on my windows form.

The error report which I get, is as follows:

Project1.vshost.exe has encountered a problem and needs to close. We are sorry for the inconvenience.

Do you perphaps know what might cause this error report whenever I click the update button?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 4
Reputation: Oblivi8or is an unknown quantity at this point 
Solved Threads: 0
Oblivi8or's Avatar
Oblivi8or Oblivi8or is offline Offline
Newbie Poster

Re: Updating a record in an MS Access database file using DataSets

 
0
  #4
Jul 2nd, 2007
Could someone please help me?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 8
Reputation: vamas is an unknown quantity at this point 
Solved Threads: 1
vamas vamas is offline Offline
Newbie Poster

Re: Updating a record in an MS Access database file using DataSets

 
0
  #5
Jul 2nd, 2007
visit web site homeandlearn.co.uk
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 812
Reputation: arjunsasidharan is on a distinguished road 
Solved Threads: 13
arjunsasidharan's Avatar
arjunsasidharan arjunsasidharan is offline Offline
Practically a Posting Shark

Re: Updating a record in an MS Access database file using DataSets

 
0
  #6
Jul 3rd, 2007
Originally Posted by Oblivi8or View Post
Could someone please help me?
Try this
There is just two ways to live your life.
One is as though nothing is a miracle.
The other is as if everything is.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 4
Reputation: Oblivi8or is an unknown quantity at this point 
Solved Threads: 0
Oblivi8or's Avatar
Oblivi8or Oblivi8or is offline Offline
Newbie Poster

Re: Updating a record in an MS Access database file using DataSets

 
0
  #7
Jul 4th, 2007
Originally Posted by arjunsasidharan View Post
Try this
Thanx buddy, you're a life saver.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 812
Reputation: arjunsasidharan is on a distinguished road 
Solved Threads: 13
arjunsasidharan's Avatar
arjunsasidharan arjunsasidharan is offline Offline
Practically a Posting Shark

Re: Updating a record in an MS Access database file using DataSets

 
0
  #8
Jul 4th, 2007
Your most welcome Oblivi.. if you got it working then you can mark the thread as SOLVED
There is just two ways to live your life.
One is as though nothing is a miracle.
The other is as if everything is.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC