469,354 Members | 2,198 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,354 developers. It's quick & easy.

importing into sql server 2005 from visual basic 2008 not creatingtable on the fly


I am trying to import a text file into a table created on the fly in
SQL Server 2005 since the number of columns can vary depending on what
the user has checked or not.

Here is the code I am using:

Dim myConnectionString As String = "Data Source=dr-ny-sql003;Initial
Catalog= TEST_TAMMY;Integrated Security=YES"
Dim myConnection As SqlConnection = New
'Dim csvInputFile As String = "R:\Spam BB Search Engine
Dim csvInputFile As String = "C:\GridExport.txt"
Dim ds As New DataSet
'Dim m_strConnection As String = "Data Source=" &
lstServers.SelectedValue & ";Initial Catalog= SpamBank;Integrated

myConnection = New SqlConnection
myConnection.ConnectionString = myConnectionString

' Make sure the .CSV file exists:
If IO.File.Exists(csvInputFile) Then
' ------ Load the data from the .CSV file: --------
Dim strSQL As String
'strSQL = "SELECT * INTO Spambank.dbo.Test_Tammy FROM
[Text;HDR=YES;DATABASE=" & csvInputFile & "]"
'strSQL = "SELECT * INTO [dr-ny-
sql003].TEST_TAMMY.dbo.Test_Tammy FROM
OPENROWSET('msdasql,Driver={Microsoft Text Driver
(*.txt;*.csv)};DEFAULTDIR=R:\Spam BB Search Engine Application\Exports
\;Extensions=txt;','select * from GridExport.txt'"
strSQL = "SELECT * INTO [dr-ny-
sql003].TEST_TAMMY.dbo.temp_test_spam FROM
OPENROWSET('msdasql,Driver={Microsoft Text Driver
(*.txt;*.csv)};DEFAULTDIR=C:\;Extensions=txt;','se lect * from

Dim objCommand As SqlClient.SqlCommand
objCommand = New SqlClient.SqlCommand(strSQL,

objCommand.CommandText = strSQL
Catch ex As Exception
MessageBox.Show("Error importing the file" &
csvInputFile & ".")
End Try
End If

I am not getting the error message, but neither is the table being
created in the database TEST_TAMMY.

What am I doing wrong?

Thanks in advanced!

Jun 27 '08 #1
0 718

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Skc | last post: by
29 posts views Thread by Natan | last post: by
1 post views Thread by =?Utf-8?B?Rmxhbm1hbg==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.