Click here to Skip to main content
12,290,514 members (69,458 online)
Click here to Skip to main content
Add your own
alternative version


16 bookmarked

How to retrieve, add, modify, and delete Oracle Data with a DataGrid

, 26 Jul 2006
Rate this:
Please Sign up or sign in to vote.
a few lines of code to do many tasks on the Oracle Data
  • <A href="DataGridEditor/"></A><A href="DataGridEditor/">Download source files - 2 Kb</A> 
  • Download demo project - 16 Kb

Sample Image - DatagridImg.jpg


            We all know that a good application is that one which the user can use easily, simply and have his jobs done quickly, I thought it will be great to have all this done by one tool and small code using a DataGrid.

This sample application shows how to Retrieve, Add, Modify, Delete Data from an Oracle Data Base.






    You have to run this sql statement on the SQL plus to create the required table:

Create table testTbl (id number(3),name varchar2(10), job varchar2(10));



If you don't have oracle tools installed on your system then install it and then add “Oracle.DataAccess.DLL” from Project => Add Reference => Brows






Dim conn As New OracleConnection("Data Source=ServiceName;User ID=UserName;Password=Password")

Dim da As OracleDataAdapter = New OracleDataAdapter

Dim ds As New DataSet

Retrieving Code

da.SelectCommand = New OracleCommand("select * from testTbl", conn)


If conn.State = ConnectionState.Closed Then conn.Open()

da.Fill(ds, "test")

myDataGrid.DataSource = ds.Tables("test")


Catch ex As Exception


End Try


Insert, Update, Delete Code

Dim param As OracleParameter

If conn.State = ConnectionState.Closed Then conn.Open()

Dim command_builder As New OracleCommandBuilder(da) 'create new command builder and passing the Dataadapter to it


da.UpdateCommand = New OracleCommand("UPDATE testTbl SET name=:name, job=:job where id=:OLDid", conn) 'building Update command

da.DeleteCommand = New OracleCommand("DELETE FROM testTbl where id=:OLDid", conn) ' building Delete command

da.UpdateCommand.Parameters.Add(":name", OracleDbType.Varchar2, 10, "name") 'Passing parameters to the command builder

da.UpdateCommand.Parameters.Add(":job", OracleDbType.Varchar2, 10, "job")

param = da.UpdateCommand.Parameters.Add(":OLDid", OracleDbType.Int32, 3, "id")

param = da.DeleteCommand.Parameters.Add(":OLDid", OracleDbType.Int32, 3, "id")

param.SourceVersion = DataRowVersion.Original

da.Update(ds, "test") 'Update Data in the Table


Catch ex As Exception


End Try


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Najeeb Al-Majidy
Web Developer
Yemen Yemen
No Biography provided

You may also be interested in...

Comments and Discussions to oracle connection Pin
DEEPAN KUMAR7-Feb-16 14:24
memberDEEPAN KUMAR7-Feb-16 14:24 
QuestionThanks Najeeb! Pin
Member 90915697-Jun-12 22:08
memberMember 90915697-Jun-12 22:08 
GeneralPerfect! Pin
Stan Zieg16-Feb-10 3:48
memberStan Zieg16-Feb-10 3:48 
This is great! It's almost impossible to find a simple implementation of these objects. Once you have 'simple' working, you can add the 'flowers' you need around it, but it has to work first. Thank you very much for the no frills explanation.
QuestionORA-12154 :TNS:Could not resolve the connect identifier specified". Pin
sushantsavant10-Feb-10 0:58
membersushantsavant10-Feb-10 0:58 
GeneralNice and easy Pin
vbsquire16-Jul-07 18:27
membervbsquire16-Jul-07 18:27 
GeneralGreat code Pin
jammoral31-May-07 7:46
memberjammoral31-May-07 7:46 
QuestionCommand Builder?? Pin
Muammar©12-Dec-06 21:56
memberMuammar©12-Dec-06 21:56 
Generalgood post Pin
sal889-Dec-06 15:22
membersal889-Dec-06 15:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160518.1 | Last Updated 27 Jul 2006
Article Copyright 2006 by Najeeb Al-Majidy
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid