Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 BCP in VB.net

Author  Topic 

cola
Starting Member

18 Posts

Posted - 2005-01-03 : 02:12:18
Hi @ All

How can I Use Bulk Copy from VB.Net ?

I have following Code

me.OleDbSelectCommand1.CommandText= bcp "SELECT * FROM Mydb..Mytable Where date < '2004-09-01'" queryout 2004.txt -c -Sprivat -Usa -Psa
Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1

Error "bcp are not declared"
Have Anybody an Idea ?

Thanks Cola

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-03 : 02:41:50
It's a string so it would be
me.OleDbSelectCommand1.CommandText= "bcp ""SELECT * FROM Mydb..Mytable Where date < '2004-09-01'"" queryout 2004.txt -c -Sprivat -Usa -Psa"

But how are you trying to call it?
If via sql server then it would be something like

me.OleDbSelectCommand1.CommandText= "exec master..xp_cmdshell 'bcp ""SELECT * FROM Mydb..Mytable Where date < ''2004-09-01''"" queryout 2004.txt -c -Sprivat -Usa -Psa"



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

cola
Starting Member

18 Posts

Posted - 2005-01-03 : 04:55:44
I have Problem with Command "EXEC"

That works:
EXEC master..xp_cmdshell 'dir *.exe'


Does not work:
1> exec master..xp_cmdshell ' bcp ""SELECT * FROM Mydb..Mytable Where date < 2004-09-01"" queryout 2004.txt -c -Sprivat -Usa -Psa'

--> The System can't find the File
Have you A simple sample with 'select*from' that works ?

Greetings Cola
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-03 : 05:10:33
What you have will work - just need to get the quotes right.
Try it from query analyser - I would put the full path in for the file created.

exec master..xp_cmdshell 'bcp "SELECT * FROM Mydb..Mytable Where date < ''2004-09-01''" queryout c:\2004.txt -c -Sprivat -Usa -Psa'

The file c:\2004.txt will be created on the server. You can view it via

exec master..xp_cmdshell 'type c:\2004.txt'


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

cola
Starting Member

18 Posts

Posted - 2005-01-03 : 05:31:07
Thanks
Sorry,this was my error. To use i gas "use master".

Greetings Cola
Go to Top of Page
   

- Advertisement -