| 发表于:2007-03-23 10:29:47 楼主 |
//添加记录方法一 /*datarow newrow=dsmy.tables[ "my "].newrow(); newrow[ "item "]=txtitem.text; newrow[ "pirce "]=txtprice.text; newrow[ "cou "]=txtcou.text; newrow[ "sum "]=convert.todouble(txtcou.text)*convert.todouble(txtprice.text); newrow[ "adddate "]=dtp.text; newrow[ "remark "]=rtremark.text; dsmy.tables[ "my "].rows.add(newrow); oledbda.update(dsmy, "my ");*/ //添加记录方法二 double dblsum=convert.todouble(txtcou.text)*convert.todouble(txtprice.text);; string addsql= "insert into my (adddate,item,pirce,cou,sum,remark) values( ' "+dtp.text+ " ', ' "+txtitem.text+ " ', "+txtprice.text+ ", "+txtcou.text+ ", "+dblsum+ ", ' "+rtremark.text+ " ') "; oledbcommand addcomm=new oledbcommand(addsql,oledbcon); rtremark.text=addsql; oledbcon.open(); addcomm.EXECutenonquery();//这里出现异常 messagebox.show( "添加记录成功 "); oledbcon.close(); ================================= sql语句是insert into my (adddate,item,pirce,cou,sum,remark) values( '2007年3月23日 ', '234 ',23,1,23, '23 '),我放到access中可以正常运行,并添加了新记录 上面第一种方法添加记录是成功的 |
|
|
|
|