473,414 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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

347 100+
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:

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head runat="server">
  7.     <title>File Upload</title>
  8.     <style type="text/css">
  9.         #form1
  10.         {
  11.             height: 60px;
  12.             width: 832px;
  13.             top: 56px;
  14.             left: 5px;
  15.             position: absolute;
  16.         }
  17.         #Submit1
  18.         {
  19.             text-align: center;
  20.             width: 69px;
  21.             top: 93px;
  22.             left: 632px;
  23.             position: absolute;
  24.             height: 26px;
  25.         }
  26.         .style1
  27.         {
  28.             text-align: center;
  29.             height: 1px;
  30.         }
  31.     </style>
  32.    </head>
  33. <body>
  34.     <form id="form1" runat="server">
  35.  <p class="style1">&nbsp;Please Upload your File Here:</p>
  36.     <p class="style1">
  37.         <asp:FileUpload ID="FileUpload1" runat="server" 
  38.             style="z-index: 1; left: 512px; top: -2px; position: absolute" />
  39.     &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;
  40.     </p>
  41.     <asp:Button ID="Button1" runat="server" 
  42.  
  43.      style="z-index: 1; left: 619px; top: 92px; position: absolute; height: 26px;" 
  44.      Text="Upload" SaveAs="C:\Inetpub\Sandbox\Files" />
  45.  
  46.      <% Dim ConnectionString
  47. ConnectionString="Driver={10.2.1.40};Server=10.2.1.40;" &_
  48. "Database=IVRDialer;Uid=xxx;Pwd=xxx;"
  49.  
  50. ALTER TABLE dialerresults
  51. (phonenumber VARCHAR(20),
  52. patientname VARCHAR(20),
  53. drname VARCHAR(30),
  54. apptdate TEXT (16),
  55. appttime TEXT (16)
  56. GO
  57. BULK
  58. INSERT dialerresults
  59. FROM 'C:\IVR test\csvtest.txt'
  60. WITH
  61. (
  62. FIELDTERMINATOR = ',',
  63. ROWTERMINATOR = '\n'
  64. )
  65. GO
  66. --Check the content of the table.
  67. SELECT *
  68. FROM dialerresults
  69. GO
  70. --Drop the table to clean up database.
  71. SELECT *
  72. FROM dialerresults
  73. GO %>
  74.  
  75. <style type="text/css">
  76. .style1 {
  77.     text-align: center;
  78. }
  79. </style>
  80.  
  81. </form>
  82. </body>
  83. </html>
  84.  
Can anyone please offer some suggestions.

Thank you

Doug
Apr 19 '10 #1
1 932
Frinavale
9,735 Expert Mod 8TB
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
Apr 27 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: cmars | last post by:
Hi, I want to insert massive amounts of data in near real-time into a MySQL database. The data is in a structured binary format, and I have code that parses the data into logical data structures. ...
2
by: Chris | last post by:
Any help would be appreciated. I am running a script that does the following in succession. 1-Drop existing database and create new database 2-Defines tables, stored procedures and functions...
2
by: Santo Santis | last post by:
How can I make an .exe file that can insert data automatically in a SQLServer database, I can do it in C, but how can I connect to SQLServer and execute a query. All data that I have to insert...
7
by: Bob | last post by:
Hi, I am trying to use BULK INSERT with format file. All of our data has few bytes of header in the data file which I would like to skip before doing BULK INSERT. Is it possible to write...
6
by: Innuendo | last post by:
Hello, I'm not a specialist with Access - so I hope that you can give me some input. I've to import xml data (about 15 different data fields) into an access-database each night. As scripting...
2
by: Zarrin | last post by:
Hello, I read several articles of newsgroup about the bulk delete, and I found one way is to: -create a temporary table with all constraints of original table -insert rows to be retained into...
20
by: TC | last post by:
I need an automated procedure to copy data from an Access table to a SQL Server table. Speed is important. What is the recommended technique? I can export the data from Access, copy it via FTP,...
0
by: tezza98 | last post by:
HI i am using BULK INSERT to copy data from a text file into a table that already exists BULK INSERT dbo.TRANStemp FROM 'D:\MSSQL\Data\TRANS.csv' WHERE dbo.TRANStemp.DateTime <> ...
8
by: =?Utf-8?B?Ym9iYnk=?= | last post by:
Could you please help me in this project. I have aTab delemeted file. It has 20 columns and some data. I have to import this data into SQL Server. I am using sql express edition. I am using...
7
by: Jon | last post by:
Hi, I plan to import some data from an old DOS-based programme. The data file format that this programme produced appears to be proprietary, but I've managed to reverse engineer the format and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.