| 发表于:2007-01-30 22:43:333楼 得分:35 |
oledbconnection mycnn = new oledbconnection( "provider=microsoft.jet.oledb.4.0;data source=f:\\dazhu12.mdb "); //新建dataset2,导入另外一个dataset中的数据 oledbdataadapter myada2 = new oledbdataadapter( "select * from t1 ", mycnn); dataset myds2 = new dataset(); myada2.fill(myds2, "tt "); datarow r = null; for (int i = 0; i < myds.tables[ "t "].rows.count; i++) { r = myds2.tables[ "tt "].newrow(); for (int j = 0; j < 5; j++) { r[j] = myds.tables[ "t "].rows[i][j].tostring(); } myds2.tables[ "tt "].rows.add(r); } this.datagridview1.datasource = myds2.tables[ "tt "].defaultview; messagebox.show( "数据导入成功! "); //更新数据库 oledbcommand mycmd = new oledbcommand( "insert into t1(id,[m_id],[t_id],[order],topic) values(@1,@2,@3,@4,@5) ", mycnn); mycmd.parameters.add( "@id1 ", system.data.oledb.oledbtype.integer, 10, "id "); mycmd.parameters.add( "@m1 ", system.data.oledb.oledbtype.integer, 10, "m_id "); mycmd.parameters.add( "@t1 ", system.data.oledb.oledbtype.integer, 10, "t_id "); mycmd.parameters.add( "@o1 ", system.data.oledb.oledbtype.integer, 10, "order "); mycmd.parameters.add( "@t2 ", system.data.oledb.oledbtype.char, 30, "topic "); myada2.insertcommand = mycmd; myada2.update(myds2, "tt "); mycnn.close(); messagebox.show( "数据更新成功! "); | | |
|