如果你只需进行一次转换,可以用SQL server 企业管理器的数据导入向导 or 在数据转换服务中完成
入你需在编程中实现,那就得用DTS(数据转换服务),具体内容可以去SQL server 的联机丛书中查阅(关键字DTS),那里有详细讲解和VB事例。
另外,程序中的DTS包,你可以利用数据导入向导\保存、调度、复制包步骤,另存为VB文件,以后在程序中直接使用
Dim dbs As Database
'打开数据库
sql = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\test.mdb;Persist Security Info=False"
dbs.Open sql
'把数据导入EXCEL
dbs.Execute "SELECT " & "PersonId as 住户编号, Name as 姓名, Sex as 性别," & _
" Birthday as 出生日期, Nation as 民族,NativePlace as 籍贯," & _
" Politics as 政治面貌, IdCard as 身份证号码,Study as 学历," & _
" WorkPlace as 工作单位, WorkPhone as 单位电话, HomePhone as 家庭电话," & _
" MobilePhone as 手机或BP机, CarCard as 车牌号码, StartDate as 入住日期," & _
" Patch as 片区, DepartmentId as 公寓号, UnitNo as 单元号," & _
" RoomId as 房间号, ContractId as 购房合同号 " & " INTO [Excel 8.0;DATABASE=" & App.Path & "\MyExcel.xls].[WorkSheet1] FROM " & "tbl_Tenement"
'关闭数据库对象
dbs.Close
'释放数据库对象
Set dbs = Nothing
19个字段,5万条记录,只需30-60秒