PDA

View Full Version : insert into SQL database


Dahquim
07-23-03, 05:19 AM
Hello.

I can program quite well in ASP/ASP.net, but was wanting to ask a question regarding something i need to do.

Each moneth we produce a file for a customer, e.g. 123001_33.csv. and i want a ASP/ASP.net page that will load this file into a SQL server database, using the first 6 characters of the file as the userID.

Does anyone have any hints, ideas, or have done this before and could let me have the code.

Thanks a lot

Dahquim

Shane
07-27-03, 08:34 PM
Originally posted by Dahquim
Hello.

I can program quite well in ASP/ASP.net, but was wanting to ask a question regarding something i need to do.

Each moneth we produce a file for a customer, e.g. 123001_33.csv. and i want a ASP/ASP.net page that will load this file into a SQL server database, using the first 6 characters of the file as the userID.

Does anyone have any hints, ideas, or have done this before and could let me have the code.

Thanks a lot

Dahquim

First, open the file. Pull off the name. Use the Mid function to grab the first 6 characters..


Dim strChars
strChars = Mid(strFileName,1,6)


Now, since a CSV file is just text, you can take the contents of the entire file after reading it into a variable, and use the Split function to split it by vbcrlf.

This will create an array that holds each line in a different space.

Loop through that array and split each value by a comma (this will get you every value). This will create yet another array of values. Loop through that array and generate your SQL statement.