get csv from the web

  • Thread starter Thread starter Antonio Policelli
  • Start date Start date
A

Antonio Policelli

hello!

i will need to write a client application that will download a csv
file from a http url like this http://www.web.com/file.csv

once the file is downloaded i will be importing it into a sql server
database table. how do i make a vb.net program download this file and
save it to my hard drive? or how do i make my vb.net program open the
file and read it from the internet. then maybe i could put it in a
datatable? how do i go about this?

AP!
 
Hi Antonio,

Once the file is downloaded, open it in vb .net using the oledb driver.
Then open the sql table using the sql client driver. Then loop through the
csv row by row and add new row to the sql table.

HTH,

Bernie Yaeger
 
Here is another way.
What happens in the code is you open the flat file and fill the Dataset with
data. Once you have that all you do is upload command on the SQL
dataaddapter and you good to go. You need to use a schema.ini file do
defilne structure of your file.
http://authors.aspalliance.com/ericm/articles/textdb.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcjetsdk_98.asp


Its not that much code. I get 800 rows in to the DB in less then 1 sec.

Dim FilePath As String = "C:\ftproot\TOG\"

Dim Conn As New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & FilePath & ";Extended Properties=""text;HDR=NO;FMT=Delimited""")

Dim Comm As New System.Data.OleDb.OleDbDataAdapter("select * from
c126927_1_sc_011504_001.txt", Conn)

Dim DS As New DataSet

Try

Comm.AcceptChangesDuringFill = False

Comm.Fill(DS)

DS.Tables(0).TableName = "scs_ds_sold_customer"

Dim objCn As New
SqlConnection("Server=NTCH27;Database=scs_auto_menu;Trusted_Connection=True;
")

Dim NwindDA As New SqlDataAdapter("select * from scs_ds_sold_customer",
objCn)

Dim x As SqlCommandBuilder = New SqlCommandBuilder(NwindDA)

objCn.Open()

NwindDA.Update(DS, "scs_ds_sold_customer")

Catch e As Exception

End Try
 
thank you bernie and ruslan, can you tell me more about how to download the csv though? when i run this app, i will download 500 csv files each one at a time and upload the data. so i have to loop through each file. this will be doing once per week. i am very interested to find out how to download the csv from in vb.net code. thank you!

AP

----- Bernie Yaeger wrote: ----

Hi Antonio

Once the file is downloaded, open it in vb .net using the oledb driver
Then open the sql table using the sql client driver. Then loop through th
csv row by row and add new row to the sql table

HTH

Bernie Yaege
 
Back
Top