1
Answer

utilizing datarow object in updating Oracle Database

mohammed ASAKER

mohammed ASAKER

13y
4.8k
1

Hi All
My Question related to VB 2008 Pro running ODP.net (11.1) and connected to Oracle Database Called RECAT which having a Table Called Clients with the following structure :

 CREATE TABLE PAYOPER.CLIENTS
(  CLNT_ID    NUMBER(4)                          NOT NULL , <== Primary Key
  CLNT_NAME  VARCHAR2(35 BYTE)                  NOT NULL,
  CLNT_EMRT  VARCHAR2(15 BYTE),
  COMP_YN    VARCHAR2(1 CHAR)
)
The following data exist in the table:-

Insert into CLIENTS
   (CLNT_ID, CLNT_NAME, CLNT_EMRT, COMP_YN)
 Values
   (1305, 'HAITHAM JAMAL ABU JAMOOS', 'SHARJAH', 'Y');
Insert into CLIENTS
   (CLNT_ID, CLNT_NAME, CLNT_EMRT, COMP_YN)
 Values
   (1306, 'JAIN LEE NOMM', 'ABU DHABI', 'Y');
Insert into CLIENTS
   (CLNT_ID, CLNT_NAME, CLNT_EMRT, COMP_YN)
 Values
   (1307, 'GEORGE KARAM HANNA', 'DUBAI', 'Y');
Insert into CLIENTS
   (CLNT_ID, CLNT_NAME, CLNT_EMRT, COMP_YN)
 Values
   (1308, 'KRISTOPHER ABI NADER', 'ABU DHABI', 'Y');

 
 
I Did a simple VB .net form to access the Datasource, taking the contents of the table to a dataset called "clnt_ds"
and do the basic Insert/Update and Delete operations to a dataset and then return the dataset back to database by the methos
DataAdapter.update

But after I'm did so I discovered that still the oracle database didn't got the update and now rows inserted nor rows updated or deleted

I need to accomplish the task by using ADO.Net Classes (DataTable,DataRow)

Can you Help Me please and here you are the code

Code:
 
 Imports Oracle.DataAccess.Client Public Class FRMCLNT Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim CONNSTR As String CONNSTR = "data source=RECAT;User ID=PAYOPER;Password=PAYOPER" Dim oracn As New OracleConnection(CONNSTR) Try oracn.Open() If oracn.State = ConnectionState.Open Then Dim orada As New OracleDataAdapter("select * from clients", oracn) Dim clnt_ds As New DataSet("clients") orada.MissingSchemaAction = MissingSchemaAction.AddWithKey orada.Fill(clnt_ds, "CLIENTS") oracn.BeginTransaction() '******************** ' ADDING RECORDS '******************** Dim tblclients As DataTable tblclients = clnt_ds.Tables("CLIENTS") Dim datarw As DataRow datarw = tblclients.NewRow datarw("CLNT_ID") = 8999 datarw("CLNT_NAME") = "Jamsheed Ishaaq " datarw("CLNT_EMRT") = "RAK" datarw("COMP_YN") = "Y" tblclients.Rows.Add(datarw) MessageBox.Show("Row Added Successfully") Dim oracmdbld As New OracleCommandBuilder(orada) orada.Update(clnt_ds, "CLIENTS") '******************** ' Edit RECORDS '******************** datarw = tblclients.Rows.Find(1305) datarw.BeginEdit() datarw("CLNT_EMRT") = "DUBAI" & datarw("COMP_YN") = "Y" datarw.EndEdit() MessageBox.Show("Row Modified Successfully" + datarw("CLNT_EMRT")) orada.Update(clnt_ds, "CLIENTS") '******************** ' Delete RECORDS '******************** datarw = tblclients.Rows.Find(1307) datarw.Delete() MessageBox.Show(" 1 Row deleted Successfully") orada.Update(clnt_ds, "CLIENTS") '******************** ' Save Changes '******************** MessageBox.Show(" DML Operations Finished" & Chr(13)) oracmdbld.Dispose() orada.Dispose() End If Catch oraex As OracleException MsgBox(oraex.Number + " - " + oraex.Message) Catch ex As Exception MessageBox.Show(ex.Message) Finally oracn.Close() oracn.Dispose() End Try End Sub End Class

 
 
Please help me to get this working noting that the code doesn't give me any error and it's showing all messageboxes as programmed but it's not updating the database.
Answers (1)