1,105,232 Community Members

Updating Access using Textbox + Button

Member Avatar
ImZick
Posting Whiz in Training
201 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 4 [?]
 
0
 

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?

Member Avatar
Begginnerdev
Veteran Poster
1,141 posts since Apr 2010
Reputation Points: 251 [?]
Q&As Helped to Solve: 191 [?]
Skill Endorsements: 15 [?]
 
0
 

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
Member Avatar
ImZick
Posting Whiz in Training
201 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 4 [?]
 
0
 

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

Member Avatar
Begginnerdev
Veteran Poster
1,141 posts since Apr 2010
Reputation Points: 251 [?]
Q&As Helped to Solve: 191 [?]
Skill Endorsements: 15 [?]
 
0
 

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")
Question Answered as of 1 Year Ago by Begginnerdev
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: