要使用.NET以编程方式复制SQL Server 2000表,您可以使用ADO.NET(ActiveX Data Objects .NET)来实现。以下是一个简单的步骤:
以下是一个示例代码:
using System;
using System.Data.SqlClient;
using System.Data;
namespace CopyTableFromSQLServer2000
{
class Program
{
static void Main(string[] args)
{
string sourceConnectionString = "Data Source=sourceServer;Initial Catalog=sourceDatabase;Integrated Security=True";
string destinationConnectionString = "Data Source=destinationServer;Initial Catalog=destinationDatabase;Integrated Security=True";
using (SqlConnection sourceConnection = new SqlConnection(sourceConnectionString))
using (SqlConnection destinationConnection = new SqlConnection(destinationConnectionString))
{
sourceConnection.Open();
destinationConnection.Open();
using (SqlCommand sourceCommand = new SqlCommand("SELECT * FROM sourceTable", sourceConnection))
using (SqlDataReader sourceDataReader = sourceCommand.ExecuteReader())
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection))
{
bulkCopy.DestinationTableName = "destinationTable";
while (sourceDataReader.Read())
{
bulkCopy.WriteToServer(sourceDataReader);
}
}
}
}
}
}
这个示例代码将源表中的数据复制到目标表中。请注意,您需要根据实际情况修改连接字符串和表名。
领取专属 10元无门槛券
手把手带您无忧上云