簡體   English   中英

C#形式的Oracle插入語句將無法正常工作?

[英]oracle insert statement with c# forms wont work?

我已經做了這個小方法,可以將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()); 
            }
        }

嘗試執行以下命令:

OracleCommand cmd = new OracleCommand();

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

或更簡單地說:

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

嘗試更改復制到輸出目錄:請勿復制

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM