困饶了一天的问题:往oracle插入数据时
PRODUCTION_ID是GUFEI.PRODUCTION的主键,非空;UNITBASIC_ID是外键和UNITBASIC表关联,也非空;
想提交5个textbox的内容到数据库啊,分别对应GUFEI.PRODUCTION表里的PRODUCTNO, PRODCODE,PUNIT,PRODNAME,PQUANTITY这5个,下面是提交button的代码:
protected void Button2_Click(object sender, EventArgs e)
{
OracleConnection conn = new OracleConnection( "Data Source=caora;User ID=gufei;Password=gufei; ");
//在此构造你所需的Sql语句。
String strSql = "Insert into GUFEI.PRODUCTION(PRODUCTION_ID,UNITBASIC_ID, PRODUCTNO, PRODCODE,PUNIT,PRODNAME,PQUANTITY) values(nvl((select max(PRODUCTION_ID) from GUFEI.PRODUCTION), 1), nvl((select max(UNITBASIC_ID) from GUFEI.PRODUCTION), 1), ' " + TextBox1.Text + " ', ' " + TextBox2.Text + " ', ' " + TextBox3.Text + " ', ' " + TextBox4.Text + " ', ' " + TextBox5.Text + " ') ";
OracleCommand cmd = new OracleCommand(strSql, conn);
cmd.Connection.Open();
//通过SqlCommand对象执行Sql命令语句即可。
cmd.ExecuteNonQuery();
执行的时候会报错:ORA-00001: 违反唯一约束条件 (GUFEI.SYS_C0020113)
弄了一天了没解决,大家帮下
------解决方案--------------------关注!
------解决方案--------------------建一个GUFEI.PRODUCTION表的序列不就可以了吗
------解决方案--------------------create sequence sq_test
start with 1
increament by 2
...
还有很多参数,具体看看书就知道了,就是生成一个自动编号生成器