使用c#表单的oracle insert语句不起作用?

时间:2013-11-23 23:33:28

标签: c# oracle

我使用这个小方法将C#表单中的数据插入到我的Oracle数据库中。代码处理得很好,但是当我去SQL Developer检查记录是否已插入时,我什么都没找到......

        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()); 
            }
        }

2 个答案:

答案 0 :(得分:1)

尝试执行如下命令:

OracleCommand cmd = new OracleCommand();

cmd.CommandText = statmentcmd;
cmd.Connection = conn;
cmd.ExecuteNonQuery();

或更简单:

OracleCommand cmd = new OracleCommand(statmentcmd, conn);
cmd.ExecuteNonQuery();

答案 1 :(得分:0)

尝试更改“复制到输出目录:不要复制”