从vb.net更新数据库

时间:2016-10-27 08:57:12

标签: sql vb.net ms-access

有没有办法可以从vb.net中的文本框更新Access数据库。我当前的程序能够显示Access数据库中的值。

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()

如何以用户可以从程序中的文本框编辑货币汇率的方式修改此程序?

1 个答案:

答案 0 :(得分:0)

您可以添加一个用作更新按钮的按钮。 再次打开连接,创建一个新的更新查询,例如

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

或者使用命令构建器,只需调用

即可
adapter.Update(ds)