hi Viktor,
"Viktor Zadro" <viktor.zadro@tel.net.ba> ha scritto nel messaggio
news:eWa3GNn7EHA.2016@TK2MSFTNGP15.phx.gbl
[quoted text, click to view] > Please help me.
>
> How export data with SQLDMO.BulkCopy (MSDE2000 + vb.net) in text file
> (export format - fixed width!!!).
you can provide a Format file...
having this kind of design:
use tempdb
CREATE TABLE test (
ID INT NOT NULL ,
Name VARCHAR(10) NOT NULL ,
Country CHAR(10) NOT NULL
)
INSERT INTO test VALUES ( 1 , 'Andrea', 'Ita' )
INSERT INTO test VALUES ( 2 , 'Viktro', 'Usa?' )
you can write a format file like
-----------
c:\tempdb_test.fmt ---------------------------------------------------------
-
8.0
3
1 SQLCHAR 0 4 "" 1 ID
""
2 SQLCHAR 0 10 "" 2 Name
Latin1_General_CI_AS
3 SQLCHAR 0 10 "\r\n" 3
Country
Latin1_General_CI_AS
---------------------------------------------------------------------
the INT column has been translated (in output) to a CHAR(4) column and the
row terminator is \r\n (new line)
then, in VB.Net,
Dim Server As SQLDMO.SQLServer
Dim bcpServer As SQLDMO.BulkCopy
Dim dbDMO As SQLDMO.Database
Dim TableDMO As SQLDMO.Table
Dim Rows As Int32
Server = New SQLDMO.SQLServer2
With Server
..AutoReConnect = True
..LoginSecure = True
..EnableBcp = True
..Connect("(local)")
End With
dbDMO = Server.Databases.Item("tempdb")
TableDMO = New SQLDMO.Table
TableDMO = dbDMO.Tables.Item("test")
bcpServer = New SQLDMO.BulkCopy
With bcpServer
..DataFilePath = "c:\exp.txt"
..ErrorFilePath = "c:\err.txt"
..DataFileType = SQLDMO.SQLDMO_DATAFILE_TYPE.SQLDMODataFile_UseFormatFile
..FormatFilePath = "c:\tempdb_test.fmt"
..LogFilePath = "c:\log.txt"
..MaximumErrorsBeforeAbort = 0
..FirstRow = 1
..UseBulkCopyOption = True
..IncludeIdentityValues = True
..UseExistingConnection = True
End With
Rows = TableDMO.ExportData(bcpServer)
Debug.WriteLine(Rows.ToString)
TableDMO = Nothing
dbDMO = Nothing
Server = Nothing
bcpServer = Nothing
and the export file will contain:
1 Andrea Ita ^this marker is mine to indicate column end .. 10
chars
2 Viktro Usa? ^this marker is mine to indicate column end .. 10
chars
--
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtm http://italy.mvps.org DbaMgr2k ver 0.9.1 - DbaMgr ver 0.55.1
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
--------- remove DMO to reply