几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量

几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 (http://www.dimcax.com/hust/index.php)
-   ObjectARX(VB.NET/C#) (http://www.dimcax.com/hust/forumdisplay.php?f=176)
-   -   【转帖】datagirdview 数据更新问题 (http://www.dimcax.com/hust/showthread.php?t=8891)

yang686526 2009-04-20 11:00 AM

【转帖】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.