![]() |
【转帖】datagirdview 数据更新问题
datagirdview 数据更新问题
www.dimcax.com datagirdview 数据更新问题 namespace chap21 { public partial class sjlr : form { datatable dt = new datatable(); oledbdataadapter da = new oledbdataadapter(); string strcon = " provider=microsoft.jet.oledb.4.0;data source=d:/c#/autoblock/database/data.mdb"; public sjlr() { initializecomponent(); } private void button1_click(object sender, eventargs e) { try { oledbcommandbuilder scb = new oledbcommandbuilder(da); da.update(dt); dt.acceptchanges(); } catch { messagebox.show("我晕倒!"); } messagebox.show("更新成功!"); } private void sjlr_load(object sender, eventargs e) { // string strcon = " provider=microsoft.jet.oledb.4.0;data source=d:/c#/autoblock/database/data.mdb"; oledbconnection myconn = new oledbconnection(strcon); myconn.open(); system.data.datatable schematable = myconn.getoledbschematable(oledbschemaguid.tables, new object[] { null, null, null, "table" }); foreach (datarow dr in schematable.rows) { //表名 combobox1.items.add(dr["table_name"]); //字段名 // datatable columntable = conn.getoledbschematable(oledbschemaguid.columns, // new object[] { null, null, dr["table_name"].tostring(), null }); } myconn.close(); } private void combobox1_selectedindexchanged(object sender, eventargs e) { oledbconnection conn = new oledbconnection(strcon); //conn.open(); string biao_name = combobox1.selecteditem.tostring(); string sql = "select * from " + biao_name + ""; oledbcommand mycommand = new oledbcommand(sql, conn); datatable dt = new datatable(); // dataset ds = new dataset(); da = new oledbdataadapter(mycommand); da.fill(dt); datagridview1.datasource = dt; } } 高手帮我看看为什么更新不了数据库! |
| 所有的时间均为北京时间。 现在的时间是 01:38 AM. |