hi all

I had make this samll method to insert data from c# forms into my oracle database the code processed fine but when I go to
sql developers software to check if the record has been inserted or not I found nothing...

so whats wrong with it please
thanks all,

        public void conn2db()
        {
            try
            {
                string connstring = "data source=test_db;user id=system;password=password;";
                string statmentcmd = "insert into register_user (userid,username,pass,fullname,phonenum,gender,country) values (" + 1 + "," + textBox1.Text + "," + textBox2.Text + "," + textBox4.Text + "," + textBox5.Text + "," + radioButtonValue+ ","+comboBox1.Text+");";

                OracleConnection conn = new OracleConnection(connstring);
                conn.Open();
                MessageBox.Show("connected to database");

                OracleCommand cmd = new OracleCommand();

                cmd.CommandText=statmentcmd;
                cmd.Connection=conn;
                OracleDataAdapter oda = new OracleDataAdapter(cmd);

                MessageBox.Show(statmentcmd);

                conn.Close();
                MessageBox.Show("Connection closed");

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString()); 
            }
        }

You don't execute any commands, of course the database wouldn't be updated when nothing is done. ;)

if u mean the

ExecuteNonQuery();

command after addinf this command i got this error message
error message img

and please if u dont mind to give me an exaple for conecting to racle databsae code with some comments that explian what each keywords do coz im the image are not really clear in my mind

thanks

Problem solved..its coused by TNS services was not running at the services

control panel >> system and secuirty >>adminstrative tools>>Computer Management >> services

last code update

public void conn2db()
        {
            try
            {
                string connstring = "data source=test_db;user id=system;password=password;";
                string statementcmd =  "insert into register_user (pid,username,pwd,fullname) values ("+'1'+"," + textBox1.Text + "," + textBox2.Text + "," + textBox4.Text + ")";

                OracleConnection conn = new OracleConnection(connstring);
                conn.Open();
                MessageBox.Show("connected to database");

                OracleCommand cmd = new OracleCommand();

                cmd.CommandText = statementcmd;
                cmd.Connection=conn;

                OracleDataAdapter oda = new OracleDataAdapter(cmd);

                MessageBox.Show(cmd.ToString());
                cmd.ExecuteNonQuery();
                conn.Close();
                MessageBox.Show("Connection closed");

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString()); 
            }
        }

but I am still had problem with insert command line

string statementcmd =  "insert into register_user (pid,username,pwd,fullname) values ("+'1'+"," + textBox1.Text + "," + textBox2.Text + "," + textBox4.Text + ")";

Error message number is ora-00984 column not allowed here

could anyone check it for me ?? is it double qoutes or single qoutes ?
or what is it please
thanks

From looking at the error's documentation I'm guessing one of your textboxes' text contains a column name. You can refer to this page to see if this is the case.
Click Here

It also gives you an example of what might be wrong.

plase if someone can tell me whats wrong with that command line

string statementcmd =  "insert into register_user (pid,username,pwd,fullname) values ("+'1'+"," + textBox1.Text + "," + textBox2.Text + "," + textBox4.Text + ")";

Try this version (encapsulated textboxes in single quotes and removed quotes from pid value)

string statementcmd =  "insert into register_user (pid,username,pwd,fullname) values ("1,'" + textBox1.Text + "','" + textBox2.Text + "','" + textBox4.Text + "')";

18 compiler errors

18 compiler errors

Unhelpful. If you're getting compiler errors, post the errors in detail and the code that the errors refer to. Otherwise you have no reason at all to expect anyone to be able to assist you in fixing them.

@deceptikon I trid to do what pitic said at previous post and I get these errors

Error 1 Too many characters in character literal C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 106 WindowsFormsApplication1
Error 2 Too many characters in character literal C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 130 WindowsFormsApplication1
Error 3 Too many characters in character literal C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 154 WindowsFormsApplication1
Error 4 Newline in constant C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 178 WindowsFormsApplication1
Error 5 ; expected C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 104 WindowsFormsApplication1
Error 6 Invalid expression term ',' C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 105 WindowsFormsApplication1
Error 7 ; expected C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 105 WindowsFormsApplication1
Error 8 ; expected C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 106 WindowsFormsApplication1
Error 9 Invalid expression term ',' C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 129 WindowsFormsApplication1
Error 10 ; expected C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 129 WindowsFormsApplication1
Error 11 ; expected C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 130 WindowsFormsApplication1
Error 12 Invalid expression term ',' C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 153 WindowsFormsApplication1
Error 13 ; expected C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 153 WindowsFormsApplication1
Error 14 ; expected C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 154 WindowsFormsApplication1
Error 15 Invalid expression term ')' C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 177 WindowsFormsApplication1
Error 16 ; expected C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 177 WindowsFormsApplication1
Error 17 ; expected C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 178 WindowsFormsApplication1
Error 18 ; expected C:\Users\Samer\documents\visual studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 101 180 WindowsFormsApplication1
Warning 19 There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "Oracle.DataAccess, Version=2.111.6.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. WindowsFormsApplication1

string statementcmd = "insert into register_user (pid,username,pwd,fullname) values (1,'" + textBox1.Text + "','" + textBox2.Text + "','" + textBox4.Text + "')";

it wasn't that had to correct... just removed a double quote near 1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.