PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 1.00 average.

ASP.NET SQL Bulk Insert

 
 
New Member
Join Date: Apr 2009
Posts: 4
 
      3rd May 2010
I have a simple upload page that will upload a file to a server and when the "upload" button is clicked, the file is uploaded to the server and then a bulk insert command is made from the .vb file. I have the database connection in the web.config file but I don't know where to add the ado connection and command structure in the .vb file. I also don't know where to put the bulk insert. I'm assuming that it goes in the .vb file as well.

Here is my .vb file as it stands currently


Partial Class _Default
Inherits System.Web.UI.Page


Private Sub Submit1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit1.ServerClick

If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then
Dim fn As String = System.IO.Path.GetFileName(File1.PostedFile.FileName)
Dim SaveLocation As String = Server.MapPath("Data") & "\" & fn
Dim fileName As String = Server.HtmlEncode(File1.FileName)
' Get the extension of the uploaded file.
Dim extension As String = System.IO.Path.GetExtension(fileName)
' Allow only files with .txt extensions' to be uploaded.
Try
File1.PostedFile.SaveAs(SaveLocation)
Response.Write(<center>Thank you for your submission.</center>)
Catch Exc As Exception
Response.Write("Error: " & Exc.Message)


End Try
Else
Response.Write(<center>Please select a file to upload.</center>)
End If

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub
End Class


Here is the bulk insert command that I need to be triggered by the ServerClick event:

bulk insert dialerresults
from '\\MSBWEB3\data\upload.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)

Select *
from dialerresults
go

The table is already created, I don't want to do a stored procedure to do this, I just need to call the connection string from the aspx.vb page and to add the bulk insert to the sub after verifying that the file in in fact uploaded and that it is in the correct format.

Can anyone assist me on how to do this?

Thank you,

Doug
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bulk insert into DB using ADO.net 1.1 utanka Microsoft ADO .NET 1 11th May 2006 08:37 PM
RE: Bulk insert? =?Utf-8?B?RWx0b24gVw==?= Microsoft ADO .NET 0 26th Mar 2006 11:50 PM
Opinions wanted: Bulk Insert vs Record Insert =?Utf-8?B?RGFsZSBGeWU=?= Microsoft Access Form Coding 2 8th Mar 2006 03:26 PM
BULK INSERT and VB.Net Mythran Microsoft ADO .NET 0 5th Apr 2005 04:41 PM
fastest way to insert data (no bulk insert, no dts) Hakan Eren Microsoft ADO .NET 3 18th Sep 2003 05:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:34 PM.