Hi

I want to update a database record using vb forms. Im using a button for this purpose...how can i do this.. is there any way like in oracle that just a commit statement save changes.. here i need to write all fields and assign their values in db... please help me.

Thanks

Dani AI

Generated

Short answer: you update rows by executing an SQL UPDATE (or by using a DataAdapter/DataSet and calling Update). asked about a single COMMIT-like call — in ADO.NET you usually either run an UPDATE with an explicit transaction (then call transaction.Commit()), or you modify an in-memory DataSet and call dataAdapter.Update(dataSet) which issues the necessary commands. and are correct that you need SQL, but use parameterized statements and a proper provider for Oracle.

Example (ASP.NET VB.NET, ODP.NET managed driver):

Imports Oracle.ManagedDataAccess.Client

Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpdate.Click
    Dim connString As String = ConfigurationManager.ConnectionStrings("MyOracle").ConnectionString
    Dim sql As String = "UPDATE my_table SET col1 = :col1, col2 = :col2 WHERE id = :id"

    Using conn As New OracleConnection(connString)
        conn.Open()
        Using tran = conn.BeginTransaction()
            Using cmd As New OracleCommand(sql, conn)
                cmd.Transaction = tran
                cmd.BindByName = True
                cmd.Parameters.Add("col1", OracleDbType.Varchar2).Value = txtCol1.Text
                cmd.Parameters.Add("col2", OracleDbType.Int32).Value = If(Integer.TryParse(txtCol2.Text, Nothing), CInt(txtCol2.Text), DBNull.Value)
                cmd.Parameters.Add("id", OracleDbType.Int32).Value = Integer.Parse(hfId.Value)
                Dim affected As Integer = cmd.ExecuteNonQuery()
                If affected = 1 Then
                    tran.Commit()
                Else
                    tran.Rollback()
                End If
            End Using
        End Using
    End Using
End Sub

Notes and troubleshooting:

  • Always use parameters (no string concatenation) to prevent SQL injection.
  • Use BindByName = True with Oracle to avoid parameter-order bugs.
  • Put connection strings in web.config and do not hardcode credentials.
  • If multiple commands must succeed together, use BeginTransaction + Commit/Rollback.
  • For a DataSet approach, fill the DataSet, let the user edit controls bound to it, then call dataAdapter.Update(...).
  • If problems occur, catch OracleException and log Number/Message for diagnosis.

For transaction basics see Microsoft docs: Transactions and Concurrency.

Recommended Answers

All 2 Replies

Hi,
What type of database engine are you using? Is it Oracle?
The code that you need to use depends on which database engine that you are using, for example an MS Access file and a MySQL Database server will require different methods of connection to the database. However once the connection has been made then it is usually just a case of sending an SQL query to the database (providing that it allows SQL queries as I have not had to deal with an oracle database yet) and that will commit the changes for you.
If you let me know which database engine you are using I will try and find the relevant code for you however another member may beat me to it... I am not sure how efficient my code is so it would be nice to see some other approaches.
Hope some of this made sense...
ParkeyParker
;-D

yes of course you have to make an sql update statement to update the record on the database

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.