944,103 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 17147
  • VB.NET RSS
Jun 30th, 2007
1

Updating a record in an MS Access database file using DataSets

Expand Post »
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.

VB.NET Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 13
Solved Threads: 0
Newbie Poster
Oblivi8or is offline Offline
4 posts
since Jun 2007
Jun 30th, 2007
0

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

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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
vamas is offline Offline
8 posts
since Jun 2007
Jun 30th, 2007
0

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

Click to Expand / Collapse  Quote originally posted by vamas ...
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?
Reputation Points: 13
Solved Threads: 0
Newbie Poster
Oblivi8or is offline Offline
4 posts
since Jun 2007
Jul 2nd, 2007
0

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

Could someone please help me?
Reputation Points: 13
Solved Threads: 0
Newbie Poster
Oblivi8or is offline Offline
4 posts
since Jun 2007
Jul 2nd, 2007
0

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

visit web site homeandlearn.co.uk
Reputation Points: 10
Solved Threads: 1
Newbie Poster
vamas is offline Offline
8 posts
since Jun 2007
Jul 3rd, 2007
0

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

Click to Expand / Collapse  Quote originally posted by Oblivi8or ...
Could someone please help me?
Try this
Reputation Points: 347
Solved Threads: 13
Practically a Posting Shark
arjunsasidharan is offline Offline
812 posts
since Aug 2006
Jul 4th, 2007
0

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

Thanx buddy, you're a life saver.
Reputation Points: 13
Solved Threads: 0
Newbie Poster
Oblivi8or is offline Offline
4 posts
since Jun 2007
Jul 4th, 2007
0

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

Your most welcome Oblivi.. if you got it working then you can mark the thread as SOLVED
Reputation Points: 347
Solved Threads: 13
Practically a Posting Shark
arjunsasidharan is offline Offline
812 posts
since Aug 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: office metadata
Next Thread in VB.NET Forum Timeline: ActiveX Control Can't create the o





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC