insert new record in oracle using datagrid

shireenrao

Active member
Joined
Jun 18, 2003
Messages
31
Location
Boston
Hello

I have a datagrid on my form. Data is retrieved into the grid using a stored procedure from oracle. My stored procedure returns a cursor. I then fill a table in a dataset with this retrieved data from the cursor, and bind it with my datagrid. here is code -

Code:
            Dim Oraclecon As New OracleConnection("SERVER=some;USER ID=some;PASSWORD=some")
            Oraclecon.Open()
            myCMD = New OracleCommand()
            myCMD.Connection = Oraclecon
            myCMD.CommandText = "package.get_Test_vals"

            myCMD.CommandType = CommandType.StoredProcedure

            Dim prm As OracleParameter = New OracleParameter("testValues", OracleType.Cursor)
            prm.Direction = ParameterDirection.Output

            myCMD.Parameters.Add(prm)


            oda = New OracleDataAdapter()
            oda.SelectCommand = myCMD
            Dim ds As New DataSet()
            oda.Fill(ds, "loadvalTable")
            Dim myLoadValTable As DataTable = ds.Tables("loadvalTable")
            DataGrid1.DataSource = myLoadValTable
            bmbGrid1 = Me.BindingContext(myLoadValTable)

where bmbGrid1 is a BindingManagerBase. I use bmbgrid to navigate the grid using buttons. e.g. first record, next record, previous record, last record.

Now I want to insert a record into the grid. I can do that, but cant figure out a way to insert it into the database. If anybody can point me to the right direction, It will be great!! I am really desperate!!

Thank you in advance

Shireen
 
Configure oda.InsertCommand (in similar manner that you configured the SelectCommand property). When you need to update the database, call oda.Update(ds, "loadvalTable").
 
Thank you Jabe

Do you know of the event to write the update in. I want to fire this event whenever there is a new record. Or should I have an explicit save button?

Thank you

Shireen
 
It would be more efficient and would involve less complexity if you had an explicit Save button. That way, the user can also undo any changes made in case he changes his mind.
 
Back
Top