TheWizardofInt
Well-known member
This should be the most basic thing you can do with ADO.Net, so of course I am baffled by it
I want to read a field in an Access table, update it, and write it back to the table.
This gives no error, but also doesnt update the field. The read ability is ok - I get the value from the field and it does increment
Where an I making what is likely a very obvious mistake?
I want to read a field in an Access table, update it, and write it back to the table.
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim oConnection As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("database/GMVAR.mdb") & ";")
Dim lNumber As Long
Build our SQL query
Dim sNumber As String
Dim cmd As New OleDb.OleDbCommand()
Dim strSQL As String = "Select Login From VARS WHere pwd=xyz123"
Dim ds As DataTable = New Data.DataTable()
Dim dc As Data.DataColumn
cmd.Connection = oConnection
cmd.CommandText = strSQL
Dim datareader As OleDb.OleDbDataAdapter
datareader = New OleDb.OleDbDataAdapter(cmd)
datareader.Fill(ds)
With ds.Rows(0)
sNumber = .Item("Login").ToString
lNumber = Val(sNumber) + 1
sNumber = CStr(lNumber)
.Item("Login") = sNumber
End With
strSQL = "Update VARS set login =" & sNumber & " where pwd=xyz123"
datareader.UpdateCommand = New OleDb.OleDbCommand(strSQL, oConnection)
oConnection.Close()
End Sub
This gives no error, but also doesnt update the field. The read ability is ok - I get the value from the field and it does increment
Where an I making what is likely a very obvious mistake?