Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataAdapter Help

Status
Not open for further replies.

BG12424

Programmer
Jun 4, 2002
717
US
I am wondering what I am doing wrong in order to use the OracleDataAdapter to grab data from the database, make changes to it in my data table, then update the database with those changes using the code I have below. Can anyone shed some light on the matter? Thanks

Code:
        Dim conn As OracleConnection = New OracleConnection("User Id=<<myuser>>;Password=<<mypass>>;Data Source=<<source>>")
        Dim ds As New DataSet

        Dim selCmd As New OracleCommand("ef_bg_test.get_adapter_test")
        selCmd.CommandType = CommandType.StoredProcedure
        selCmd.Parameters.Add(New OracleParameter("io_cursor_out", OracleType.Cursor, 0, ParameterDirection.Output, True, 0, 0, "", DataRowVersion.Default, Convert.DBNull))
        selCmd.Connection = conn

        Dim da As New OracleDataAdapter(selCmd)
        da.Fill(ds)

        Dim row2 As DataRow = ds.Tables(0).Rows(2)
        row2(0) = "Test3"
        row2(1) = "JohnDoe"

        Dim row4 As DataRow = ds.Tables(0).Rows(4)
        row4(0) = "Test5"
        row4(1) = "JanDoe"

        ds.AcceptChanges()

        Dim updCmd As New OracleCommand("ef_bg_test.update_adapter_test")
        updCmd.CommandType = CommandType.StoredProcedure
        updCmd.Parameters.Add(New OracleParameter("column1_in", OracleType.VarChar, 50, "TestColumn1"))
        updCmd.Parameters.Add(New OracleParameter("column2_in", OracleType.VarChar, 50, "TestColumn2"))
        da.UpdateCommand = updCmd

        Dim cb As New OracleCommandBuilder(da)
        Try
            da.Update(ds)

            Dim dg As New DataGrid
            dg.DataSource = ds
            dg.DataBind()
            Page.Controls.Add(dg)

        Catch ex As Exception
            Throw ex
        Finally
            conn.Close()
        End Try

regards,
Brian
The problem with doing something right the first time is that nobody appreciates how difficult it was.
 
Ok, I figured it out...Thanks

Code:
        Dim conn As OracleConnection = New OracleConnection("User Id=<<user>>;Password=<<pass>>;Data Source=<<source>>")
        Dim ds As New DataSet

        'Build the select command
        Dim selCmd As New OracleCommand("ef_bg_test.get_adapter_test")
        selCmd.CommandType = CommandType.StoredProcedure
        selCmd.Parameters.Add(New OracleParameter("io_cursor_out", OracleType.Cursor, 0, ParameterDirection.Output, True, 0, 0, "", DataRowVersion.Default, Convert.DBNull))
        selCmd.Connection = conn
        Dim da As New OracleDataAdapter(selCmd)

        'Fill dataset based on select statement
        da.Fill(ds)
        Dim row2 As DataRow = ds.Tables(0).Rows(2)
        row2(0) = "Test3"
        row2(1) = "Marv"
        Dim row4 As DataRow = ds.Tables(0).Rows(4)
        row4(0) = "Test5"
        row4(1) = "Kevin"

        'Build the update command
        Dim updCmd As New OracleCommand("ef_bg_test.update_adapter_test")
        updCmd.CommandType = CommandType.StoredProcedure
        updCmd.Parameters.Add("column1_in", OracleType.VarChar, 50, "TestColumn1")
        updCmd.Parameters.Add("column2_in", OracleType.VarChar, 50, "TestColumn2")
        updCmd.Connection = conn
        da.UpdateCommand = updCmd

        Try
            Dim modRows() As DataRow = ds.Tables(0).Select("", "", DataViewRowState.ModifiedCurrent)
            da.Update(modRows)
        Catch ex As Exception
            Throw ex
        Finally
            conn.Close()
        End Try

regards,
Brian
The problem with doing something right the first time is that nobody appreciates how difficult it was.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top