I have a simple browse and upload web page that users can upload a .csv file to a server and then a bulk insert is ran after the user clicks the "upload" button.
Here is my default.aspx code:
@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns="<head runat="server">
<title>Upload Page</title>
<style type="text/css">
#form1
{
height: 128px;
}
#File1
{
top: 66px;
}
#Submit1
{
top: 103px;
left: 591px;
}
#TextArea1
{
z-index: 1;
left: 303px;
top: 45px;
position: absolute;
}
</style>
<script language="javascript" type="text/javascript">
// <!CDATA[
function Submit1_onclick() {
}
// ]]>
</script>
</head>
<body>
<form id="form1" enctype="multipart/form-data" runat="server">
<br />
<br />
<input type="File" id="File1" name="File1" runat="server"
style="position: absolute; left: 512px;" />
<br />
<input type="Submit" id="Submit1" value="Upload" runat="server"
style="position: absolute; height: 30px;"
onclick="return Submit1_onclick()" /> </p>
</form>
</body>
</html>
Here is my .vb code:
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
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
I want to do a bulk insert without a stored procedure and here is the bulk insert (which has been tested and works)
bulk insert dialerresults
from '\\MSBWEB3\data\test.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
Select *
from dialerresults
go
What I need to know is where is the best place to put the onclick event handler? Is it in the .vb script? Is the database connection string better in the web.config file then the onclick would call that event with the SQL script written into the page? I want to make this as efficient as possible and I've never made a page like this before.
Any help would be greatly appreciated.
Thank you
Doug
Here is my default.aspx code:
@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns="<head runat="server">
<title>Upload Page</title>
<style type="text/css">
#form1
{
height: 128px;
}
#File1
{
top: 66px;
}
#Submit1
{
top: 103px;
left: 591px;
}
#TextArea1
{
z-index: 1;
left: 303px;
top: 45px;
position: absolute;
}
</style>
<script language="javascript" type="text/javascript">
// <!CDATA[
function Submit1_onclick() {
}
// ]]>
</script>
</head>
<body>
<form id="form1" enctype="multipart/form-data" runat="server">
<br />
<br />
<input type="File" id="File1" name="File1" runat="server"
style="position: absolute; left: 512px;" />
<br />
<input type="Submit" id="Submit1" value="Upload" runat="server"
style="position: absolute; height: 30px;"
onclick="return Submit1_onclick()" /> </p>
</form>
</body>
</html>
Here is my .vb code:
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
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
I want to do a bulk insert without a stored procedure and here is the bulk insert (which has been tested and works)
bulk insert dialerresults
from '\\MSBWEB3\data\test.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
Select *
from dialerresults
go
What I need to know is where is the best place to put the onclick event handler? Is it in the .vb script? Is the database connection string better in the web.config file then the onclick would call that event with the SQL script written into the page? I want to make this as efficient as possible and I've never made a page like this before.
Any help would be greatly appreciated.
Thank you
Doug