如何用c#将服务器A中的数据库复制到服务器B中

如题所述

补充你的函数体:
string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\A.mdb;";
string comString1 = @"select * into [n] from [D:\B.mdb].[n]";

基本就是这样(默认服务器和架构一致),最好你还写一个判断A数据库原本有没有这个表n,防止重复插入。

下面是判断表有无存在的方法
public static bool tableExist(string tableName)
{
try
{
string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data.mdb;";
OleDbConnection conn = new OleDbConnection(connString);
conn.Open();
DataTable dt = conn.GetSchema("Tables");
conn.Close();
DataRow[] drs = dt.Select(string.Format("TABLE_TYPE='TABLE' and TABLE_NAME='{0}'", tableName));
if (drs.Length > 0)
{
return true;
}
else
{
return false;
}
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
return false;
}
}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答
大家正在搜