Urgent help Please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • teddymeu
    New Member
    • Feb 2007
    • 19

    #1

    Urgent help Please

    Hi Guys

    i write a thread before asking for help with reading an uploaded csv file,

    i have my code, it reads the csv file and currently displays it in a datagrid but what i actually want is to take the read information and import it into my sql express db.

    Heres the code

    Code:
    <script runat="server">    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            If (IsPostBack) Then
                Grid1.Visible = True
            Else
                Grid1.Visible = False
            End If
        End Sub
        Sub UploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            'Save the uploaded file to an "Uploads" directory
            ' that already exists in the file system of the 
            ' currently executing ASP.NET application.  
            ' Creating an "Uploads" directory isolates uploaded 
            ' files in a separate directory. This helps prevent
            ' users from overwriting existing application files by
            ' uploading files with names like "Web.config".
            Dim saveDir As String = "\Data\"
               
            ' Get the physical file system path for the currently
            ' executing application.
            Dim appPath As String = Request.PhysicalApplicationPath
                
            ' Before attempting to save the file, verify
            ' that the FileUpload control contains a file.
            If (FileUpload1.HasFile) Then
                Dim savePath As String = appPath + saveDir + FileUpload1.FileName
                            
                ' Call the SaveAs method to save the 
                ' uploaded file to the specified path.
                ' This example does not perform all
                ' the necessary error checking.               
                ' If a file with the same name
                ' already exists in the specified path,  
                ' the uploaded file overwrites it.
                FileUpload1.SaveAs(savePath)
                    
                ' Notify the user that the file was uploaded successfully.
                UploadStatusLabel.Text = "Your file was uploaded successfully."
    
            Else
                ' Notify the user that a file was not uploaded.
                UploadStatusLabel.Text = "You did not specify a file to upload."
            End If
    
        End Sub
        
        Sub DisplayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\inetpub\wwwroot\MerlinLocalPostOfficeApp\Data;Extended Properties=""text;HDR=NO;FMT=Delimited"""
            Dim objConn As New OleDbConnection(sConnectionString)
            objConn.Open()
            Dim objCmdSelect As New OleDbCommand("SELECT * FROM csv.txt", objConn)
            Dim objAdapter1 As New OleDbDataAdapter()
            objAdapter1.SelectCommand = objCmdSelect
             Dim objDataset1 As New DataSet()
            objAdapter1.Fill(objDataset1, "csv.txt")
            Grid1.DataSource = objDataset1.Tables(0).DefaultView
            Grid1.DataBind()
            objConn.Close()
        End Sub
        
        
      </script>
    My csv file does not have headers so the default value is F1, F2, F3 F4, F5,F6, F7, my database has 7 columns, ID,AddressLine1 ,AddressLine2,A ddressLine3,Add ressLine4,Addre ssLine5,Address Line6,Postcode

    I need to know how to import the information direct into the db rather than displaying it on the page, ive tried but im really new to this and cant get it to work. I cant use DTS or bulk insert as the server this will go on doesnt have sql on it, the db is an MDF file so is transportable with the app.

    Thanks for your help
  • SaintPatrick
    New Member
    • Feb 2007
    • 9

    #2
    First, I'm thinking that having an .mdf without an instance of SQL Server to attach to is fairly useless. Check the following usenet post for support Google Usenet Posting

    So, thats rough and might need rethinking.

    Second, to not display we just don't bind it to a control that renders to the page. Instead, we can read the .csv into a dataset, get a dataset of the table we pushing to and get on with life.

    Store procedure would be good for this though. Cheers.

    Comment

    Working...