欢迎来到天天文库
浏览记录
ID:42604887
大小:24.52 KB
页数:7页
时间:2019-09-18
《C#处理access数据库结构》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C#处理access数据库结构usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Data.OleDb;usingSystem.Data;usingSystem.Windows.Forms;namespaceNewUserControl{publicclassAccessTableCopy{//////获取两个数据库的路径//////老数据库的路径2、m>///新数据库的路径publicvoidGetTwoAccessConnection(stringoldpath,stringnewpath){OleDbConnectionnewconnection;stringconnStr="Provider=Microsoft.ACE.OLEDB.12.0;DataSource="+newpath+";PersistSecurityInfo=False";newconnection=newOleDbConnection(conn3、Str);stringoldconnStr="Provider=Microsoft.ACE.OLEDB.12.0;DataSource="+oldpath+";PersistSecurityInfo=False";OleDbConnectionoldconnection;oldconnection=newOleDbConnection(oldconnStr);this.BatchUpdate(newconnection,oldconnection,oldpath);}//////批量执行更新数据///4、ary>///新数据库的连接///旧数据库的连接///老数据库的路径publicvoidBatchUpdate(OleDbConnectionnewconnection,OleDbConnectionoldconnection,stringoldpath){//获取旧数据库中的表列表Listoldtablelist=th5、is.GetTableName(oldconnection);//获取新的数据库中的表Listnewtablelist=this.GetTableName(newconnection);for(inti=0;i6、(oldtablename.ToLower()==newtablename.ToLower()){//获取老数据库表中的表字段,并处理成符合sql标准Listlistold=this.GetTableColumn(oldtablename,oldconnection);stringoldcolumns="";string[]columnname=newstring[listold.Count];foreach(stringlstinlistold){oldcolumns+=lst+",";}oldcolumns=o7、ldcolumns.Remove(oldcolumns.LastIndexOf(","),1);oldcolumns.Trim();//生成sql语句stringsql="";sql="insertinto"+oldtablename+"("+oldcolumns+")select"+oldcolumns+"from[;database="+oldpath+";]."+oldtablename+"";using(OleDbCommandcommand=newOleDbCommand(sql,newconnection)){newc8、onnection.Open();command.ExecuteNonQuery();newconnection.Close();}//获取指定表的主关键字段名称string[]spiltname=this.PrimaryKeyName(oldta
2、m>///新数据库的路径publicvoidGetTwoAccessConnection(stringoldpath,stringnewpath){OleDbConnectionnewconnection;stringconnStr="Provider=Microsoft.ACE.OLEDB.12.0;DataSource="+newpath+";PersistSecurityInfo=False";newconnection=newOleDbConnection(conn
3、Str);stringoldconnStr="Provider=Microsoft.ACE.OLEDB.12.0;DataSource="+oldpath+";PersistSecurityInfo=False";OleDbConnectionoldconnection;oldconnection=newOleDbConnection(oldconnStr);this.BatchUpdate(newconnection,oldconnection,oldpath);}//////批量执行更新数据///4、ary>///新数据库的连接///旧数据库的连接///老数据库的路径publicvoidBatchUpdate(OleDbConnectionnewconnection,OleDbConnectionoldconnection,stringoldpath){//获取旧数据库中的表列表Listoldtablelist=th5、is.GetTableName(oldconnection);//获取新的数据库中的表Listnewtablelist=this.GetTableName(newconnection);for(inti=0;i6、(oldtablename.ToLower()==newtablename.ToLower()){//获取老数据库表中的表字段,并处理成符合sql标准Listlistold=this.GetTableColumn(oldtablename,oldconnection);stringoldcolumns="";string[]columnname=newstring[listold.Count];foreach(stringlstinlistold){oldcolumns+=lst+",";}oldcolumns=o7、ldcolumns.Remove(oldcolumns.LastIndexOf(","),1);oldcolumns.Trim();//生成sql语句stringsql="";sql="insertinto"+oldtablename+"("+oldcolumns+")select"+oldcolumns+"from[;database="+oldpath+";]."+oldtablename+"";using(OleDbCommandcommand=newOleDbCommand(sql,newconnection)){newc8、onnection.Open();command.ExecuteNonQuery();newconnection.Close();}//获取指定表的主关键字段名称string[]spiltname=this.PrimaryKeyName(oldta
4、ary>///新数据库的连接///旧数据库的连接///老数据库的路径publicvoidBatchUpdate(OleDbConnectionnewconnection,OleDbConnectionoldconnection,stringoldpath){//获取旧数据库中的表列表Listoldtablelist=th
5、is.GetTableName(oldconnection);//获取新的数据库中的表Listnewtablelist=this.GetTableName(newconnection);for(inti=0;i6、(oldtablename.ToLower()==newtablename.ToLower()){//获取老数据库表中的表字段,并处理成符合sql标准Listlistold=this.GetTableColumn(oldtablename,oldconnection);stringoldcolumns="";string[]columnname=newstring[listold.Count];foreach(stringlstinlistold){oldcolumns+=lst+",";}oldcolumns=o7、ldcolumns.Remove(oldcolumns.LastIndexOf(","),1);oldcolumns.Trim();//生成sql语句stringsql="";sql="insertinto"+oldtablename+"("+oldcolumns+")select"+oldcolumns+"from[;database="+oldpath+";]."+oldtablename+"";using(OleDbCommandcommand=newOleDbCommand(sql,newconnection)){newc8、onnection.Open();command.ExecuteNonQuery();newconnection.Close();}//获取指定表的主关键字段名称string[]spiltname=this.PrimaryKeyName(oldta
6、(oldtablename.ToLower()==newtablename.ToLower()){//获取老数据库表中的表字段,并处理成符合sql标准Listlistold=this.GetTableColumn(oldtablename,oldconnection);stringoldcolumns="";string[]columnname=newstring[listold.Count];foreach(stringlstinlistold){oldcolumns+=lst+",";}oldcolumns=o
7、ldcolumns.Remove(oldcolumns.LastIndexOf(","),1);oldcolumns.Trim();//生成sql语句stringsql="";sql="insertinto"+oldtablename+"("+oldcolumns+")select"+oldcolumns+"from[;database="+oldpath+";]."+oldtablename+"";using(OleDbCommandcommand=newOleDbCommand(sql,newconnection)){newc
8、onnection.Open();command.ExecuteNonQuery();newconnection.Close();}//获取指定表的主关键字段名称string[]spiltname=this.PrimaryKeyName(oldta
此文档下载收益归作者所有