User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 426,476 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,244 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 5888 | Replies: 7 | Solved
Reply
Join Date: Jun 2007
Posts: 4
Reputation: Oblivi8or is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Oblivi8or's Avatar
Oblivi8or Oblivi8or is offline Offline
Newbie Poster

Question Updating a record in an MS Access database file using DataSets

  #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.

Dim con As New OleDb.OleDbConnection
        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        Dim sql As String


        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\bin\MY_DATABASE.mdb"
        con.Open()

        sql = "SELECT * FROM client WHERE ID = 1"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "ClientList")

        con.Close()
'filling the corresponding textbox named txtName which I have on my windows form
        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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Posts: 8
Reputation: vamas is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
vamas vamas is offline Offline
Newbie Poster

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

  #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  
Join Date: Jun 2007
Posts: 4
Reputation: Oblivi8or is an unknown quantity at this point 
Rep Power: 0
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

  #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  
Join Date: Jun 2007
Posts: 4
Reputation: Oblivi8or is an unknown quantity at this point 
Rep Power: 0
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

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

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

  #5  
Jul 2nd, 2007
visit web site homeandlearn.co.uk
Reply With Quote  
Join Date: Aug 2006
Location: India
Posts: 812
Reputation: arjunsasidharan is on a distinguished road 
Rep Power: 4
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

  #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  
Join Date: Jun 2007
Posts: 4
Reputation: Oblivi8or is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Oblivi8or's Avatar
Oblivi8or Oblivi8or is offline Offline
Newbie Poster

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

  #7  
Jul 4th, 2007
Originally Posted by arjunsasidharan View Post
Try this


Thanx buddy, you're a life saver.
Reply With Quote  
Join Date: Aug 2006
Location: India
Posts: 812
Reputation: arjunsasidharan is on a distinguished road 
Rep Power: 4
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

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 4:05 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC