We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,745 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Updating Access using Textbox + Button

Hi guys i have this code which insert the data in the textbox

    Dim FilePath As String = "C:\Users\ezekiels\Desktop\New Folder\EBU 6.mdb"
    Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & FilePath & "")
    conn.Open()
    Dim myadapter As New OleDbDataAdapter("SELECT * FROM Table_EBU6", conn)
    Dim dtset As New DataSet
    myadapter.Fill(dtset)
    myadapter.Dispose()

    Dim table As DataTable = dtset.Tables(0)

    Me.Jan_Revenue2.Text = table.Rows(0).Item(1)
    Me.Feb_Revenue2.Text = table.Rows(1).Item(1)
    Me.Mar_Revenue2.Text = table.Rows(2).Item(1)

    conn.close

what if i need to edit the Textbox and the record will update in access?

2
Contributors
3
Replies
1 Day
Discussion Span
3 Months Ago
Last Updated
12
Views
Question
Answered
Zick Technology
Junior Poster
183 posts since Dec 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 3

I use the following methods when I am editing data:

Dim Con as New OleDBConnection("MyStringHere")
Dim da As New OleDBDataAdapter("SELECT * FROM table",Con)
Dim ds As New DataSet

Try
   Con.Open()
   da.Fill(ds,"MyTable")

   ds("MyTable").Rows(0)("ColumName") =  Me.Jan_Revenue2.Text 
   ds("MyTable").Rows(1)("ColumName") =  Me.Feb_Revenue2.Text 
   ds("MyTable").Rows(2)("ColumName") =  Me.Mar_Revenue2.Text 

   da.UpdateCommand = New Data.OleDb.OleDbCommandBuilder(da).GetUpdateCommand
   da.Update(ds.Tables("MyTable"))
Catch ex As Exception
    MsgBox(ex.ToString)
Finally
    Con.Close()
End Try
Begginnerdev
Practically a Posting Shark
861 posts since Apr 2010
Reputation Points: 184
Solved Threads: 141
Skill Endorsements: 8

I got an error in this code

ds("MyTable").Rows(0)("ColumName") = Me.Jan_Revenue2.Text
ds("MyTable").Rows(1)("ColumName") = Me.Feb_Revenue2.Text
ds("MyTable").Rows(2)("ColumName") = Me.Mar_Revenue2.Text 

system.data.dataset' cannot be indexed because it has no default property

the higlighted value is the ds

Zick Technology
Junior Poster
183 posts since Dec 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 3

My appologies. I had typed that code into the editor without a copy of VS handy.

Replace:

ds("MyTable").Rows(0)("ColumnName")

with

ds.Tables("MyTable").Rows(0)("ColumnName")
Begginnerdev
Practically a Posting Shark
861 posts since Apr 2010
Reputation Points: 184
Solved Threads: 141
Skill Endorsements: 8
Question Answered as of 2 Months Ago by Begginnerdev

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0631 seconds using 2.65MB