C 實現複製資料庫 C 將A資料庫資料轉到B資料庫

2022-09-26 03:51:11 字數 1230 閱讀 1932

本文章以乙個表為例,要轉多個表則可將dataset關聯多個表,下面給出完整**,包括引用以及main函式與複製函式。

要說明的是,必須先用sql語句複製表結構,才能順利的使用以下**複製資料。

using system;

using system.collections.generic;

using system.lbnkhlqrjinq;

using system.text;

using system.data;

using system.data.sqlclient;

using system.data.common;

namespace copydata

//引數為兩個資料庫的連線字串

private static void inserttable(string constring1, string constring2, string tabstr)

sqldataadapter adapter2 = new sqldataadapter("select * from " + tabstr, conn2);

dataset dataset2 = new dataset();

sqlcommand cmd2 = new sqlcommand("select count(*) from " + tabstr, conn2);

object res2 = cmd2.executescalar();

if (res2 != null)

} //填充dataset2

if (dataset2 != null)

//複製資料

for (int j = 0; j < dataset2.tables[0].rows.count; j++)

//將dataset變換顯示在與其關聯的目標資料庫

sqlcommandbuilder cb = new sqlcommandbuilder(adapter1);

adapter1.update(dataset1, tabstr);

cb.refr程式設計客棧eshschema();

console.writeline("表" + tabstr + "複製成功!");

conn1.close();

conn2.close();

} } }

本文標題: c#實現複製資料庫 c#將a資料庫資料轉到b資料庫

本文位址:

C 複製資料庫,將資料庫資料轉到另乙個資料庫

本文章以乙個表為例,要轉多個表則可將dataset關聯多個表,下面給出完整 包括引用以及main函式與複製函式。要說明的是,必須先用sql語句複製表結構,才能順利的使用以下 複製資料。using system using system.collections.generic using system...

複製資料庫

複製資料庫 sql200企業管理器 右鍵要複製的資料庫a 所有任務 匯出資料 目標資料庫,選擇資料庫b 然後選擇 在sql server資料庫之間複製資料和物件 勾選 建立目的物件 包含擴充套件屬性 最後完成.或者查詢分析器執行下面的語句建立乙個儲存過程,然後再執行呼叫示例中的呼叫方法實現資料庫複製...

資料庫複製

if exists select from dbo.sysobjects where id object id n dbo p copydb and objectproperty id,n isprocedure 1 drop procedure dbo p copydb go 資料庫資料複製 將乙...