Here is your solution in ASP.NET
made w/ Visual Studio. It would have
to be transferred (along with associated files
over to a virtual directory
in IIS on the SQL machine.
Code:
Imports System.web
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
'DATA
'**********
Dim var_sqlconnection As New SqlConnection
Dim var_sqldataadapter As New SqlDataAdapter
Dim var_sqldataset As New DataSet
Dim var_sqlselectcommand As New SqlCommand
Dim var_sqlinsertcommand As New SqlCommand
Dim var_sqldeletecommand As New SqlCommand
Dim var_sqlcommandbuilder As New SqlCommandBuilder
'**********
Dim var_readline As String
Dim var_sql As String
Dim var_string As String
Dim var_sqlconnectionstring As String = "data source=SERVER;initial catalog=DATABASE;persist security info=False;user " & _
"id=USER;password=PASSWORD;packet size=4096"
var_streamreader = File.OpenText(var_file)
Do
var_readline = var_streamreader.ReadLine
var_string = var_readline
'IGNORE FIRST LINE, IF NECESSARY
If (Mid(var_readline, 1, 3) <> "SOMETHING UNIQUE TO FIRST LINE") Then
Dim var_one As Integer
Dim var_two As Integer
Dim var_three As Integer
Dim var_four As Integer
Dim var_five As String
Dim var_count As Integer
Dim var_temp As String
'***EXTRACT VALUES FROM CSV ***
Try
'PAYRID
var_count = InStr(var_string, ",", CompareMethod.Text)
var_one = Mid(var_string, 1, (var_count - 1))
var_temp_string = Mid(var_string, (var_count + 1))
var_string = var_temp_string
var_count = InStr(var_string, ",", CompareMethod.Text)
var_two = Mid(var_string, 1, (var_count - 1))
var_temp_string = Mid(var_string, (var_count + 1))
var_string = var_temp_string
var_count = InStr(var_string, ",", CompareMethod.Text)
var_three = Mid(var_string, 1, (var_count - 1))
var_temp_string = Mid(var_string, (var_count + 1))
var_string = var_temp_string
var_count = InStr(var_string, ",", CompareMethod.Text)
var_four = Mid(var_string, 1, (var_count - 1))
var_temp_string = Mid(var_string, (var_count + 1))
var_string = var_temp_string
var_five = Mid(var_string, 1)
Catch ex As Exception
'ERROR CODE HERE ***
End Try
'UPLOAD TO DB ***
var_sql = ("INSERT INTO ROUTE_1 " & _
"VALUES(var_one, " & _
"var_two, " & _
"var_three, " & _
"var_four, " & _
"var_five)")
Try
var_sqlconnection.ConnectionString = var_sqlconnectionstring
var_sqlinsertcommand.CommandType = CommandType.Text
var_sqlinsertcommand.CommandText = var_sql
var_sqldataadapter.InsertCommand = var_sqlinsertcommand
var_sqldataadapter.InsertCommand.Connection = var_sqlconnection
var_sqldataadapter.InsertCommand.Connection.Open()
var_sqldataadapter.InsertCommand.ExecuteNonQuery()
var_sqldataadapter.InsertCommand.Connection.Close()
Catch Iex As Exception
'ERROR CODE HERE ***
End Try
End If
Loop Until (var_readline Is Nothing)
var_streamreader.Close()
var_streamreader.Dispose()
I had hoped to stay away from a solution such as this
as it requires Visual Studio and a understanding of
that whole process.
When you get this working, you need to create
a simple task to detect if the csv file has been transferred
and then to kick this program off.
BTW...
The "code behind" ASP.NET language
used was VB.
Any questions (I know you have some), let me know
and we can work through it.
Good Luck
Bookmarks