Posting data to a file then doing a bulk insert to a database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dougancil
    Contributor
    • Apr 2010
    • 347

    Posting data to a file then doing a bulk insert to a database

    I am relatively new to .net and have created a page that is using a file input control and an upload button. What I would like this page to do is load the file to a directory on the server (saving a copy of the file) then executing a bulk insert to a sql database after the file has been submitted. I have 2 problems

    1. I can't get the file to save to the server.
    2. I have no idea how to fire the bulk insert script off after that.

    Here is my code thus far:

    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>File Upload</title>
        <style type="text/css">
            #form1
            {
                height: 60px;
                width: 832px;
                top: 56px;
                left: 5px;
                position: absolute;
            }
            #Submit1
            {
                text-align: center;
                width: 69px;
                top: 93px;
                left: 632px;
                position: absolute;
                height: 26px;
            }
            .style1
            {
                text-align: center;
                height: 1px;
            }
        </style>
       </head>
    <body>
        <form id="form1" runat="server">
     <p class="style1">&nbsp;Please Upload your File Here:</p>
        <p class="style1">
            <asp:FileUpload ID="FileUpload1" runat="server" 
                style="z-index: 1; left: 512px; top: -2px; position: absolute" />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </p>
        <asp:Button ID="Button1" runat="server" 
            
         style="z-index: 1; left: 619px; top: 92px; position: absolute; height: 26px;" 
         Text="Upload" SaveAs="C:\Inetpub\Sandbox\Files" />
         
         <% Dim ConnectionString
    ConnectionString="Driver={10.2.1.40};Server=10.2.1.40;" &_
    "Database=IVRDialer;Uid=xxx;Pwd=xxx;"
    
    ALTER TABLE dialerresults
    (phonenumber VARCHAR(20),
    patientname VARCHAR(20),
    drname VARCHAR(30),
    apptdate TEXT (16),
    appttime TEXT (16)
    GO
    BULK
    INSERT dialerresults
    FROM 'C:\IVR test\csvtest.txt'
    WITH
    (
    FIELDTERMINATOR = ',',
    ROWTERMINATOR = '\n'
    )
    GO
    --Check the content of the table.
    SELECT *
    FROM dialerresults
    GO
    --Drop the table to clean up database.
    SELECT *
    FROM dialerresults
    GO %>
    
    <style type="text/css">
    .style1 {
        text-align: center;
    }
    </style>
    
    </form>
    </body>
    </html>
    Can anyone please offer some suggestions.

    Thank you

    Doug
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Why can't you get the file to the server?

    Check out the documentation for the FileUpload control for information about how to use this control.

    -Frinny

    Comment

    Working...