• Notice regarding image hosts and attachments. See here.

Text files and SQL insert problem

Associate
Joined
18 Oct 2002
Posts
972
Location
Derby
This is probably really easy but it's been doing my head in for a while and I wonder if any of you guys could shed some light on this or tell me what I am doing wrong.

Basically I have a CSV file of names. This looks like the following

Code:
Dave Smith
John Smith
Paul Smith

The below code is quite primitive for testing purposes but what I want it to do is:

Read first name of file
Use a SQL statement to insert this name into a table called NAMES
Read second name of file
Insert second name to database

and so on until all names are read and inserted.

Here is my method for doing this:

Code:
Sub readText(s As Object, E As Eventargs)
      Dim objStreamReader As StreamReader
      Dim strInput As String

      output = " "
      objStreamReader = File.OpenText("C:\Temp\names.csv")
      strInput = objStreamReader.ReadLine()
      objConn.Open()
      While (strInput <> Nothing)

      output &= strInput & "<br />"

      strInput = objStreamReader.ReadLine()
      Dim queryString As String = "INSERT INTO [NAME] ([name]) VALUES (& "output" &)"



      objCmd = New OleDbCommand
      objCmd.CommandText = queryString
      objCmd.Connection = objConn
      objCmd.ExecuteNonQuery()

      End While
      objStreamReader.Close()
      objConn.Close()
      End Sub

I gather it is a syntax problem with "output" but for the life of me I can't figure it out. If i try 'output' it literally writes 'output' to the database and anything else I try gives me parameter errors etc..

Any ideas or help really appreciated. I know it's something simple as it always is with me. Thanks for your time.
 
Back
Top Bottom