473,804 Members | 3,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQLDMO.BulkCopy

Hi all I am trying to do a Bulk Copy from a "tab delmimited" text file to a
table in my database. I have it almost working except when the file has
too few columns for the table (table has 421 columns).

Some of my the files will have 419 columns some others files will have 421
columns.

When my bulk insert script encounters a file with 419 colums it will put
some of the data from the next line in the last 2 columns.
I tried creating a DTS package with a bulk insert and I get the same out
come.
Here is my test script can anyone help
'--------------------------------------------------------------

<%
Dim objServer: Set objServer = Server.CreateOb ject("SQLDMO.SQ LServer")
Dim objBCP: Set objBCP = Server.CreateOb ject("SQLDMO.Bu lkCopy")
Dim objDB: Set objDB = Server.CreateOb ject("SQLDMO.Da tabase")

dim BulkCopy
dim objTable
dim item
dim g_strUploadPath : g_strUploadPath =Server.MapPath ("../DOC2/")&"\upload \"

dim strFileName: strFileName = g_strUploadPath & "ex_test.tx t"

'if file doesn't exist and it's an import,
'don't waste time (too be add later)
'If Import = True And Dir(FileName) = "" Then Exit Function

'On Error GoTo ErrorHandler
objServer.Conne ct "XXX.XXX.XX.XX" , "XXX", "XX"
objServer.Enabl eBcp = 1

Set objDB = objServer.Datab ases("Advia120v 2_dev")
With objBCP
.DataFilePath = strFileName

.UseBulkCopyOpt ion = True

'tab delmitted, carriage return line feed ends row
.DataFileType = 2
'.ColumnDelimit er = chr(9)
'.RowDelimiter = chr(13) & chr(10)
.IncludeIdentit yValues = False
End With
objDB.Tables("H emo_193_39552_3 9").ImportDa ta objBCP
'BCP = True

'ErrorHandler:
'Set objBCP = Nothing
'Set objServer = Nothing
%>
'--------------------------------------------------------------
thanks
Jul 20 '05 #1
3 7960
silven <si****@removes ilven.canada.co m> wrote in message news:<Xn******* *************** *******@206.167 .113.5>...
Hi all I am trying to do a Bulk Copy from a "tab delmimited" text file to a
table in my database. I have it almost working except when the file has
too few columns for the table (table has 421 columns).

Some of my the files will have 419 columns some others files will have 421
columns.

When my bulk insert script encounters a file with 419 colums it will put
some of the data from the next line in the last 2 columns.
I tried creating a DTS package with a bulk insert and I get the same out
come.
Here is my test script can anyone help
'--------------------------------------------------------------

<%
Dim objServer: Set objServer = Server.CreateOb ject("SQLDMO.SQ LServer")
Dim objBCP: Set objBCP = Server.CreateOb ject("SQLDMO.Bu lkCopy")
Dim objDB: Set objDB = Server.CreateOb ject("SQLDMO.Da tabase")

dim BulkCopy
dim objTable
dim item
dim g_strUploadPath : g_strUploadPath =Server.MapPath ("../DOC2/")&"\upload \"

dim strFileName: strFileName = g_strUploadPath & "ex_test.tx t"

'if file doesn't exist and it's an import,
'don't waste time (too be add later)
'If Import = True And Dir(FileName) = "" Then Exit Function

'On Error GoTo ErrorHandler
objServer.Conne ct "XXX.XXX.XX.XX" , "XXX", "XX"
objServer.Enabl eBcp = 1

Set objDB = objServer.Datab ases("Advia120v 2_dev")
With objBCP
.DataFilePath = strFileName

.UseBulkCopyOpt ion = True

'tab delmitted, carriage return line feed ends row
.DataFileType = 2
'.ColumnDelimit er = chr(9)
'.RowDelimiter = chr(13) & chr(10)
.IncludeIdentit yValues = False
End With
objDB.Tables("H emo_193_39552_3 9").ImportDa ta objBCP
'BCP = True

'ErrorHandler:
'Set objBCP = Nothing
'Set objServer = Nothing
%>
'--------------------------------------------------------------
thanks


To bulk load a data file with fewer columns than the table, you can
use a format file - see "Using a Data File with Fewer Fields" in Books
Online in the section on BCP.

If only some of your files are incorrect, then you need to somehow
identify them before loading, and set the .FormatFilePath property
only if needed.

Simon
Jul 20 '05 #2
sq*@hayes.ch (Simon Hayes) wrote in
news:60******** *************** ***@posting.goo gle.com:
silven <si****@removes ilven.canada.co m> wrote in message
news:<Xn******* *************** *******@206.167 .113.5>...
Hi all I am trying to do a Bulk Copy from a "tab delmimited" text
file to a table in my database. I have it almost working except when
the file has too few columns for the table (table has 421 columns).

Some of my the files will have 419 columns some others files will
have 421 columns.

When my bulk insert script encounters a file with 419 colums it will
put some of the data from the next line in the last 2 columns.
I tried creating a DTS package with a bulk insert and I get the same
out come.
Here is my test script can anyone help
'--------------------------------------------------------------

<%
Dim objServer: Set objServer =
Server.CreateOb ject("SQLDMO.SQ LServer") Dim objBCP: Set objBCP =
Server.CreateOb ject("SQLDMO.Bu lkCopy") Dim objDB: Set objDB =
Server.CreateOb ject("SQLDMO.Da tabase")

dim BulkCopy
dim objTable
dim item
dim g_strUploadPath : g_strUploadPath
=Server.MapPath ("../DOC2/")&"\upload \"

dim strFileName: strFileName = g_strUploadPath & "ex_test.tx t"

'if file doesn't exist and it's an import,
'don't waste time (too be add later)
'If Import = True And Dir(FileName) = "" Then Exit Function

'On Error GoTo ErrorHandler
objServer.Conne ct "XXX.XXX.XX.XX" , "XXX", "XX"
objServer.Enabl eBcp = 1

Set objDB = objServer.Datab ases("Advia120v 2_dev")
With objBCP
.DataFilePath = strFileName

.UseBulkCopyOpt ion = True

'tab delmitted, carriage return line feed ends row
.DataFileType = 2
'.ColumnDelimit er = chr(9)
'.RowDelimiter = chr(13) & chr(10)
.IncludeIdentit yValues = False
End With
objDB.Tables("H emo_193_39552_3 9").ImportDa ta objBCP
'BCP = True

'ErrorHandler:
'Set objBCP = Nothing
'Set objServer = Nothing
%>
'--------------------------------------------------------------
thanks


To bulk load a data file with fewer columns than the table, you can
use a format file - see "Using a Data File with Fewer Fields" in Books
Online in the section on BCP.

If only some of your files are incorrect, then you need to somehow
identify them before loading, and set the .FormatFilePath property
only if needed.

Simon


I am not sure if format files will work because I can never tell if the
file I am importing from has 419 or 421 columns.

If I use the import function in SQL Server, if I import a file that has
419 columns the remainning will be filled with NULLs, I need to duplicate
that. Do you think it can be done with format files
Thanks

silven
Jul 20 '05 #3
<snip>

I am not sure if format files will work because I can never tell if the
file I am importing from has 419 or 421 columns.

If I use the import function in SQL Server, if I import a file that has
419 columns the remainning will be filled with NULLs, I need to duplicate
that. Do you think it can be done with format files
Thanks

silven


As I said, if you can identify the number of columns before uploading,
then you can set the FormatFile property or not, as you need to. Since
you're doing this in VB, you could easily open the text file and count
the delimiters in the first line to work this out.

The extra two columns will be set to NULL, assuming that they are
NULLable and don't have DEFAULT constraints. Since it works with the
Import tool, that's probably a safe assumption.

Simon
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6670
by: ewm | last post by:
Using InstallShield Developer 7.04. Does anyone know of a good way to detect if SQLDMO is installed? TIA mcpoo
1
6344
by: Mohammed Abdel-Razzak | last post by:
Dear sirs I`ve used SQLDMO to make a backup to my database How can I use it to restore database? thanks Mohammed
3
5314
by: T. | last post by:
I dumped VB and adopted C# for this version of Visual Studio. My problem! I am trying to reference an SQLDMO.Database object in C# like so: private SQLDMO.Database dbcurrent; private string dbname; dbname = "Northwind"; dbcurrent = (SQLDMO.Database)sqlsvr.Databases.Item(dbname); But I get this error : No overload for method 'Item' takes '1' arguments.
1
1749
by: C# beginner | last post by:
Hi all, I am using SQLDMO.Backup for backing up SQL server databases. I need to implement a progress bar to show the progress. I have some sample VB code that is like this: Dim WithEvents oBackupEvent As SQLDMO.Backup Set oBackupEvent = oBackup ' enable events
1
7567
by: | last post by:
Hi all My requirement is to "on button_click, backup a SQL database using SQLDMO.Backup object and update the progress in a ProgressBar. The problem is the progress bar does not update at all until the very end of the backup process, when the backup is almost going to be over, the progress bar updates itself once on a stretch, which is no use,it is not showing any progress. SQLDMO documentation says, the SQLDMO.Backup object fires
2
5523
by: | last post by:
Hi all, continued from yesterday's posting... I still haven't found a solution to this issue. I put a breakpoint in private void SqlBackupPercentComplete(string message, int Percent) { progressBar1.Value = Percent; progressBar1.Update(); }
1
2559
by: | last post by:
Hi all I am posting this to check if anyone could help me. The problem still persists. I am beginner in C#. Thanks. Subject: SQLDMO.Backup and ProgressBar - help please From: "anonymous@discussions.microsoft.com" <anonymous@discussions.microsoft.com> Sent: 11/11/2004 5:52:10 AM
0
1703
by: wisaunders | last post by:
the file I'm importing has > 200,000 records I have one problem: One of the columns in the .txt file (customerID) has almost all Inetger values except for about 30 records. Those 30 records have one letter in the customerID field (M123456). The field they are going into is VARCHAR(1000) . All of the integers go in correctly but for some reason the cutomerID values that stert with a letter (M123456) are NULL. Any help? I'm stumped. ...
3
2593
by: Nils | last post by:
I use SQLDMO.Bulkcopy in an VB6 (have to) program to load data from a plain text file into a SQL Server 2000. One of the target columns is NOT NULL but it happens that I receive a missing value for that column in the source file. BulkCopy then has an ODBC error raised that complains about the violated NOT NULL constraint. The Bulkcopy error file however is empty. Is there a way to figure out in which row of the source file the error...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10327
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7625
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.