问题描述
privatevoidbutton1_Click(objectsender,EventArgse){OdbcConnectionOCsrc=newOdbcConnection("dsn=src;uid=sa;pwd=sss;database=src");OdbcDataAdapterDAsrc=newOdbcDataAdapter("select*fromitem",OCsrc);OdbcConnectionOCdst=newOdbcConnection("dsn=dst;uid=sa;pwd=123;database=test");OdbcDataAdapterDAdst=newOdbcDataAdapter("select*fromitem_dst",OCdst);OdbcCommandBuilderCB=newOdbcCommandBuilder(DAdst);DataSetDS_src=newDataSet();DataSetDS_dst=newDataSet();DAsrc.TableMappings.Add("Table","src");DAdst.TableMappings.Add("Table","dst");DAsrc.Fill(DS_src);DAdst.Fill(DS_dst);DataTableDTsrc=DS_src.Tables["src"];DataTableDTdst=DS_dst.Tables["dst"];OCdst.Open();DS_dst.Tables["dst"].Merge(DS_src.Tables["src"]);dataGridView1.DataSource=DS_dst.Tables["dst"];DAdst.Update(DS_dst);OCdst.Close();}
解决方案
解决方案二:
1:Update不支持同时更新两个表的2:一般要更新的话需加上OdblCommandBuilderob=newOdbcCommandBuilder(要更新的OdbcDataAdapter);3:对于你的这个需求建议你把DataSet一个一个的更新OdblCommandBuilderob=newOdbcCommandBuilder(DAsrc);DAsrc.Update(DS_src)OdblCommandBuilderob=newOdbcCommandBuilder(DAdst);DAsrc.Update(DS_dst)PS:你这两个捞出来的数据结构应该都是一样的吧