ADO.NET Update into Access DB

fpineda101

Well-known member
Joined
Nov 14, 2005
Messages
122
Location
Los Angeles, CA
Programming Experience
1-3
Hello

I'm coding this project which is supposed to be a mock ATM. The screen of the ATM is a label. I'm using the datareader and oledbcommands for the select. I am able to authenticate a user with their account no and pin.

What I want to do is update the balance of the account and insert a new row into a transaction table which stores the info from the transaction. Under ADO.NET and oledb, how would I issue an Update command and Insert command to the account and transaction tables respectively.

Below is the code I am using for the select. I tried passing a string parameter with an update command but nothing happens...

My question is, how do I pass an update command to the ExecuteSQL sub routine? Much thanks for your help!

Private Const ACCESS_CONNECT_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\VB Examples\ATM V2\bin\BANK.mdb;User Id=admin;Password=;"

dim AccessDBConnection As OleDbConnection
dim AccessDBCommand As OleDbCommand
dim AccessDBDataReader As OleDbDataReader

Public Sub ConnectDB()
AccessDBConnection =
New OleDbConnection(ACCESS_CONNECT_STRING)
AccessDBConnection.Open()
'open the connection
End Sub

Public Sub OpenDataset(ByVal inSQL As String) 'for selects
ConnectDB()
AccessDBCommand =
New OleDbCommand(inSQL, AccessDBConnection)
AccessDBDataReader = AccessDBCommand.ExecuteReader(CommandBehavior.CloseConnection)
End Sub

Public Sub ExecuteSQL(ByVal inSQL As String) 'for updates and inserts
AccessDBCommand =
New OleDbCommand(inSQL, AccessDBConnection)
End Sub

 
I've seen some examples that might help. I tried this, doesn't work but can someone point me in the right direction? Please help!

Public Sub ExecuteSQL(ByVal inSQL As String)
AccessUpdate =
New OleDbCommand(inSQL, AccessDBConnection)
AccessUpdate.ExecuteNonQuery()
CloseConnection()
'AccessDBCommand = New OleDbCommand(inSQL, AccessDBConnection)
End Sub
 
Issue Resolved

Problem solved. Don't need to pass parameters other than the actual SQL string. The sub routine to execute DML statements goes as follows...

Public Sub ExecuteSQL(ByVal inSQL As String)
Dim accCON As New OleDbConnection
Dim accCOMMAND As New OleDbCommand

accCON =
New OleDbConnection(ACCESS_CONNECT_STRING)
accCOMMAND.CommandText = inSQL
accCOMMAND.Connection = accCON

accCON.Open()
accCOMMAND.ExecuteNonQuery()
accCON.Close()
End Sub
 
Back
Top