| 发表于:2007-01-30 15:38:11 楼主 |
我在vs2005 里面要插入一个dbf 的数据库.但不知道怎么写,请各位帮忙 using adodb; public void run() //查询是可以啦 { connection cn = new connection(); recordset rec = new recordset(); // string strcnn = "microsoft.jet.oledb.4.0;data source=f:\\djkq;extended properties=dbase iv;user id=admin;password= "; string filename = @ "f:\djkq\qtsj.dbf "; // string strcnn = "provider=microsoft.jet.oledb.4.0;data source=f:\\djkq;extended properties=dbase iv;user id=admin;password= "; string strcnn = @ "provider=microsoft.jet.oledb.4.0;data source= " + filename.substring(0, filename.lastindexof( "\\ ") + 1) + @ ";extended properties= " "dbase iv;hdr=yes; " "; "; string strsql = "select * from qtsj.dbf "; try { cn.open(strcnn, " ", " ", -1); rec.open(strsql, cn, cursortypeenum.adopenstatic, locktypeenum.adlockreadonly, -1); while (!rec.eof) { messagebox.show(rec.fields[1].value.tostring()); rec.movenext(); } rec.close(); cn.close(); } catch (exception ex) { messagebox.show(ex.message); } } public void runadd()//新增 一直写不进去 { connection cn = new connection(); recordset rec = new recordset(); // string strcnn = "microsoft.jet.oledb.4.0;data source=f:\\djkq;extended properties=dbase iv;user id=admin;password= "; string filename = @ "f:\djkq\qtsj.dbf "; // string strcnn = "provider=microsoft.jet.oledb.4.0;data source=f:\\djkq;extended properties=dbase iv;user id=admin;password= "; string strcnn= @ "provider=microsoft.jet.oledb.4.0;data source= " + filename.substring(0, filename.lastindexof( "\\ ") + 1) + @ ";extended properties= " "dbase iv;hdr=yes; " "; "; string insertsql = "insert into qtsj(gh,rq,hs1,ms1) values( '888888 ', '20070130 ',7,12) "; try { cn.open(strcnn, " ", " ", -1); rec.open(insertsql, cn,cursortypeenum.adopenstatic,locktypeenum.adlockreadonly,-1); // rec.addnew( "gh,rq,hs1,ms1 ", " '888888 ', '20070130 ',7,12 "); // rec.addnew( "gh ", "888888 "); rec.update(); rec.close(); cn.close(); } catch (exception ex) { messagebox.show(ex.message); } |
|
|
|
|