Nishan Fernando Nishan Fernando - 1 month ago 8
SQL Question

Update database from vb.net

Is there a way I can update an Access database from text boxes in vb.net. My current program is capable of display the values from an Access database.

Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged

Dim ds As New DataSet

Dim sql As String =
"Select TOP 1 GEUR,GUSD FROM GBPtb WHERE Date= ?"

Using connection As New OleDb.OleDbConnection(strConnectionString),
command As New OleDb.OleDbCommand(sql, connection),
adapter As New OleDb.OleDbDataAdapter(command)

connection.Open()


How can I modify this program in a way that the user will be able to edit the currency exchange rates from the textboxes in the program?

Answer

You can add a button which serves as the Update button. Open the connection again, create a new update query for example,

Dim updateStr As String ="UPDATE yourTable SET col1 = col1 + 1"
Dim myCommand As New OleDbCommand(updateStr,yourConnection)
myCommand.ExecuteNonQuery()

Or make use of command builder where you can just call

adapter.Update(ds)
Comments