Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Updating a database with vb.net from a gridview

strangermikeJun 3 2009 — edited Jun 3 2009
Hello,
This is my first attempt at updating an Oracle database from code (vb.net 2005), (Oracle 9i). In the past i have only updated access databases. I got through the connection and read processes to fill gridviews, and I see that Oracle is really no different then access, only object names have changed.

I'm not sure if this is the case with the updates. Below is a sample of an Access update. Can you post a sample of an oracle update?
Are parameters handled differently? (And below this is my incorrect attempt at the Oracle update)

******a working Access update *****

Protected Sub GridView3_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView3.RowCommand
Dim NewConnection As New OleDbConnection
NewConnection.ConnectionString = ConfigurationManager.ConnectionStrings("MyConnection").ConnectionString

If e.CommandName = "Update" Then
Try
Dim strDepartName = CType(GridView3.Rows(CInt(e.CommandArgument)).FindControl("txtDepartName"), TextBox).Text
Dim txtDepartNum = CType(GridView3.Rows(CInt(e.CommandArgument)).FindControl("lblDepartNum"), Label).Text

NewConnection.Open()
Dim trans As OleDbTransaction = NewConnection.BeginTransaction(IsolationLevel.ReadCommitted)
Dim cmd As New OleDbCommand("Update tblDepart set DepartName=? " & _
"Where DepartNum=?", NewConnection, trans)

cmd.Parameters.Add(New OleDb.OleDbParameter("DepartName", strDepartName))
cmd.Parameters.Add(New OleDb.OleDbParameter("DepartNum", txtDepartNum))

cmd.ExecuteNonQuery()
trans.Commit()
GridView3.EditIndex = -1
NewConnection.Close()
BindDepartments()
Me.lblInfo.Text = "Update Complete"

Catch ex As Exception
Throw ex
End Try
End If

End Sub


***************I know this is wrong on many levels, can you post one that works? *************
If e.CommandName = "Update" Then
Try
Dim NewOracleConnection As New OracleConnection()
NewOracleConnection.ConnectionString = ConfigurationManager.ConnectionStrings("MyOracleConnection").ConnectionString

Dim strGoalAmount = CType(GridView3.Rows(CInt(e.CommandArgument)).FindControl("txtGoalAmount"), TextBox).Text

Dim trans As OracleTransaction = NewOracleConnection.BeginTransaction(IsolationLevel.ReadCommitted)
Dim cmd As New OracleCommand

NewOracleConnection.Open()

cmd.CommandText = "Update zsalespersongoals set GoalAmount=:I_GoalAmount " & _
"Where SalesPerson_Id=:I_Salesperson_ID"

Dim parmGoalAmount = New OracleParameter("I_GoalAmount", OracleDbType.BinaryFloat)
Dim parmSalesPerson = New OracleParameter("I_Salesperson_Id", OracleDbType.Varchar2)
parmSalesPerson = 52
parmGoalAmount = strGoalAmount

cmd.ExecuteNonQuery()
trans.Commit()
GridView3.EditIndex = -1
NewOracleConnection.Close()

Catch ex As Exception
Throw ex
End Try
End If
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 1 2009
Added on Jun 3 2009
1 comment
411 views