ninel
Active member
I have a csv file that is selected by a user. The csv file contains one column (phone number). I need to import this file into a table on sql server using vb.net.
I've tried the following code:
I'm getting an error: "Invalid object name 'C:\VoicenetSQL\project\tampa\Politic\JH2468\at1008.CSV'."
This is the file the user selected.
What am I doing wrong?
Any help would be greatly appreciated,
Ninel
I've tried the following code:
VB.NET:
Dim objConn As nsSqlClient.SqlConnection
Dim ds As New DataSet
Dim m_strConnection As String = "server=NINEL-D246655F1;Initial Catalog=TimeControl;user id=timeuser;password=timeuser;"
objConn = New nsSqlClient.SqlConnection
objConn.ConnectionString = m_strConnection
objConn.Open()
' Make sure the .CSV file exists:
If File.Exists(sLeadFile) Then
Try
' ------ Load the data from the .CSV file: --------
Dim strSQL As String
strSQL = "SELECT F1 " & _
"INTO " & projectfile & ".dbo.[List_staging] " & _
"FROM [Text;HDR=NO;DATABASE=" & sLeadFile & "]"
Dim objCommand As nsSqlClient.SqlCommand
objCommand = New nsSqlClient.SqlCommand(strSQL, objConn)
objCommand.CommandText = strSQL
objCommand.ExecuteNonQuery()
objConn.Close()
Catch ex As Exception
sResultText = sResultText & "<BR>" & ex.Message
End Try
End If
This is the file the user selected.
What am I doing wrong?
Any help would be greatly appreciated,
Ninel