Click here to Skip to main content
15,887,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone,

I am newly started C# and also oracle. I am developing a phone book at c#. I am Using Oracle DB. I have completed insert, delete, search. However, I cant update the information. Please help me. That is my first question. Sorry for my ignorance.
I list the records on a gridtable. Then I double click the left side of any record on grid table. Then the update panel which is filled the information of the current record is opened. There is no problem until here. However my update button does not work.
Here is my Update Button Code.
C#
OracleConnection con = new OracleConnection("Data Source=O10G;User Id=plsql_staj;Password=*****;");
           con.Open();
           string query = "UPDATE TEL_REHBERI SET AD ='" + txtGnclAd.Text.ToUpper() + "' , SOYAD ='" + txtGnclSoyad.Text.ToUpper() + "' , YAS = '" + txtGnclYas.Text.ToUpper() + "' , CEP_NO = '" + txtGnclCep.Text.ToUpper() + "' , EV_NO = '" + txtGnclEv.Text.ToUpper() + "', DOGUMYERI = '" + txtGnclDogumYeri.Text.ToUpper() + "' WHERE AD ='"++ "' AND SOYAD = '" + txtGnclSoyad.Text.ToUpper() + "' AND YAS ='" + txtGnclYas.Text.ToUpper() + "' AND CEP_NO = '" + txtGnclCep.Text.ToUpper() + "' AND EV_NO ='" + txtGnclCep.Text.ToUpper() + "' AND DOGUMYERI = '" + txtGnclDogumYeri.Text.ToUpper() + "' ";
           DataSet ds = new DataSet();// Dataset
           OracleDataAdapter da = new OracleDataAdapter(query, con); // DataAdapter olustur
           OracleCommand cmd = new OracleCommand(query, con);
           bool result = Convert.ToBoolean(cmd.ExecuteNonQuery());
           da.Fill(ds); // DataAdapteri Kullanarak Dataset içindeki Verilere erişti
           con.Close();


In my form I am using the same textboxes. I will Add two ss and hope this will help.
1st ss:
http://www.imagetoo.com/images/ss1aua.png
2nd ss:
http://www.imagetoo.com/images/ss2vuv.png
I need Help. Thanx.
Posted
Updated 24-Jul-12 22:36pm
v5

Dear turan,

Is there any identity field in your table, update your record on basis of an identity field not with Textfield. and Try to use parameterized query, so No SQL injection will distroy your data.

SQL
string query = "UPDATE TEL_REHBERI SET AD ='" + txtGnclAd.Text.ToUpper() + "' , SOYAD ='" + txtGnclSoyad.Text.ToUpper() + "' , YAS = '" + txtGnclYas.Text.ToUpper() + "' , CEP_NO = '" + txtGnclCep.Text.ToUpper() + "' , EV_NO = '" + txtGnclEv.Text.ToUpper() + "', DOGUMYERI = '" + txtGnclDogumYeri.Text.ToUpper() + "' WHERE <code>id="+reheberi_ID+" </code>";



Thanks
Ashish
 
Share this answer
 
Comments
FoxRoot 25-Jul-12 7:03am    
Sorry Does not work. Thanx for your polite helps.
Try this

C#
OracleConnection con = new OracleConnection("Data Source=O10G;User Id=plsql_staj;Password=*****;");
con.Open();
string query = string.Format("UPDATE TEL_REHBERI SET AD ='{0}', SOYAD ='{1}', YAS = '{2}', CEP_NO = '{3}' , EV_NO = '{4}', DOGUMYERI = '{5}' WHERE AD ='{0}' AND SOYAD = '{1}' AND YAS ='{2}' AND CEP_NO = '{3}' AND EV_NO ='{4}' AND DOGUMYERI = '{5}'",txtGnclAd.Text.ToUpper() , txtGnclSoyad.Text.ToUpper(), txtGnclYas.Text.ToUpper() ,txtGnclCep.Text.ToUpper() ,txtGnclEv.Text.ToUpper() , txtGnclDogumYeri.Text.ToUpper());

DataSet ds = new DataSet();// Dataset
OracleDataAdapter da = new OracleDataAdapter(query, con); // DataAdapter olustur
OracleCommand cmd = new OracleCommand(query, con);
bool result = Convert.ToBoolean(cmd.ExecuteNonQuery());
da.Fill(ds); // DataAdapteri Kullanarak Dataset içindeki Verilere erişti
con.Close();
 
Share this answer
 
v2
Comments
FoxRoot 25-Jul-12 7:03am    
Thanx but this didint solve.
sachin10d 27-Jul-12 3:17am    
Can you elaborate on what exactly you want to achieve
FoxRoot 1-Aug-12 5:07am    
sachin10d thanks for your kindly helping. I want to update information by using same textbox. Please check my screanshots When I click the object that I want to update a window is opened with the information. I want to change them.
Is there anybody to solve this? Please
 
Share this answer
 
Comments
Mohamed Mitwalli 25-Jul-12 6:03am    
Could you stop doing that !!! if you have comment , you can comment on any solution or on your Question but don't Add a solution .
FoxRoot 25-Jul-12 7:01am    
As I mentioned in my post, I am new here.I havent seen that solution / comment are seperate objects. I am sorry for this. Could you stop doing dictatorship.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900