Link to home
Start Free TrialLog in
Avatar of janviero
janviero

asked on

VS2008 VB.net Excel.csv load into sql2000 assistance

Hi Pros!

I am a newbie that is trying to insert a .csv into sql 2000 using a web page I created. I was able to make it work in vb6 and Access, but am lost in vs2008/Sql. Could you look at my code and tell me what I am missing? I see so many different methods on the web I do not know what is what any more. One particular issue I am having with this no is the spaces in the names: [Parameter 1].

Is there no easy wizard to set all this up? Your help is realllllly appreciated!
Imports Microsoft.Office.Interop
Imports System.Data.SqlClient
Imports System.IO
Imports Microsoft.Office.core
Imports System.Web.DynamicData
Imports System.Data
Imports System.Web.UI.HtmlControls
Imports System.Data.OleDb
Imports System.Configuration




Partial Public Class _Default
    Inherits System.Web.UI.Page
    Protected WithEvents FileName As System.Web.UI.HtmlControls.HtmlGenericControl
    Protected WithEvents FileContent As System.Web.UI.HtmlControls.HtmlGenericControl
    Protected WithEvents FileSize As System.Web.UI.HtmlControls.HtmlGenericControl
    Protected WithEvents postedFile As System.Web.UI.HtmlControls.HtmlInputFile
    '    Protected WithEvents Span1 As System.Web.UI.HtmlControls.HtmlGenericControl
    '    Protected WithEvents Span2 As System.Web.UI.HtmlControls.HtmlGenericControl
    '    Protected WithEvents UploadDetails As System.Web.UI.HtmlControls.HtmlGenericControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
    Protected Severity As String
    Protected Computer As String
    Protected Source As String
    Protected [Alert Name] As Char
    Protected [Date] As DateTime
    Protected Time As DateTime
    Protected [Parameter 1] As string
    Protected [Parameter 2] As string
    Protected [Parameter 3] As string
    Protected [Parameter 4] As string
    Protected [Parameter 5] As string
    Protected [Parameter 6] As string


    Public Sub btnload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoad.Click



        If FileUpload1.HasFile Then

            Dim postedFile As System.Web.HttpPostedFile = FileUpload1.PostedFile
            Dim FileName As String = Path.GetFileName(postedFile.FileName)
            Dim FileContent As String = postedFile.ContentType
            Dim FileSize As Integer = postedFile.ContentLength

        End If






        Dim strSQL As String
        strSQL = "INSERT INTO tblVirusScan(Severity, Computer, Source, [Alert Name], [Date], [Time], [Parameter 1], [Parameter 2], [Parameter 3], [Parameter 4], [Parameter 5], [Parameter 6])" & _
             "VALUES(" & Severity & ", '" & Computer & "', '" & Source & "', '" & "Alert Name" & "', '" & [Date] & "', '" & [Time] & "', '" & "Parameter 1" & "', '" & "Parameter 2" & "', '" & "Parameter 3" & "', '" & "Parameter 4" & "', '" & "Parameter 5" & "', '" & "Parameter 6" & "','" & FileUpload1.PostedFile.FileName & "','" & FileUpload1.PostedFile.ContentType & "', '" & FileUpload1.PostedFile.ContentLength & "')"


        Dim myConnection As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("VirusScanConnectionString2").ConnectionString)
        myConnection.Open()
        Dim myCommand As SqlCommand = New SqlCommand(strSQL, myConnection)
        myCommand.CommandType = Data.CommandType.Text
        myCommand.ExecuteNonQuery()
        myConnection.Close()

Open in new window

SOLUTION
Avatar of Reza Rad
Reza Rad
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial