我已經使這個小的方法從C#表單插入數據到我的Oracle數據庫。該代碼處理很好,但是當我去SQL Developer來檢查記錄已被插入或沒有,我什麼也沒找到......用c#形式的oracle插入語句不會工作?
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());
}
}
你應該逃避字符串或更好的是,在你的命令中使用參數。通過TNS服務致毒 –
問題solved..its未在服務 控制面板>>系統和secuirty >>智優工具>>計算機管理>>服務運行 但我仍然有與插入命令行的問題 string statementcmd =「insert into register_user(pid,username,pwd,fullname)values(」+'1'+「,」+ textBox1.Text +「,」+ textBox2.Text +「,」+ textBox4.Text +「) 「; 錯誤消息編號是ora-00984列不允許在這裏 任何人都可以檢查它嗎?它是雙重qoutes還是單一qoutes? 或它是什麼請 謝謝 – sam