473,395 Members | 1,941 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,395 software developers and data experts.

Data being submitted twice

347 100+
I have the following aspx.vb page:

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Imports System.Data
  3. Imports System.Data.SqlClient
  4. Partial Class _Default
  5.     Inherits System.Web.UI.Page
  6.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  7.  
  8.     End Sub
  9.     Protected Sub Submit1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit1.Click
  10.         Dim SaveLocation = "\\MSBWEB3\wwwroot\Webfile1\Data\upload.txt"
  11.         If UploadFile(SaveLocation) Then
  12.             'the file was uploaded: now try saving it to the database
  13.             SaveToDatabase(SaveLocation)
  14.         End If
  15.     End Sub
  16.     Private Function UploadFile(ByVal SavePath As String) As Boolean
  17.         Dim fileWasUploaded As Boolean = False 'indicates whether or not the file was uploaded
  18.  
  19.         'Checking if the file upload control contains a file
  20.         If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then
  21.             Try
  22.                 'checking if it was .txt file BEFORE UPLOADING IT!
  23.                 'You used to upload it first...but the file could be a virus
  24.                 If File1.FileName.EndsWith(".txt") = False Then
  25.                     'The file is not the expected type...do not upload it
  26.                     'just post the validation message
  27.                     message.Text = "The file you submitted is not a .txt file, please select a .txt file to upload."
  28.                 Else
  29.                     'The file is a .txt file
  30.                     'checking to see if the file exists already
  31.                     'If it does exist Deleting the existing one so that the new one can be created
  32.                     If IO.File.Exists(SavePath) Then
  33.                         IO.File.Delete(SavePath)
  34.                     End If
  35.  
  36.                     'Now upload the file (save it to your server)
  37.                     File1.PostedFile.SaveAs(SavePath)
  38.  
  39.                     'After saving it check to see if it exists
  40.                     If File.Exists(SavePath) Then
  41.                         'Upload was sucessful
  42.                         message.Text = "Thank you for your submission"
  43.                         fileWasUploaded = True
  44.                     Else
  45.                         'the file was not saved
  46.                         message.Text = "Unable to save the file"
  47.                     End If
  48.                 End If
  49.  
  50.             Catch Exc As Exception
  51.                 'We encountered a problem
  52.                 message.Text = Exc.Message + " " + Exc.StackTrace
  53.             End Try
  54.         Else
  55.             'No file was selected for uploading
  56.             message.Text = "Please select a file to upload"
  57.         End If
  58.         Return fileWasUploaded
  59.     End Function
  60.  
  61.     Private Sub SaveToDatabase(ByVal SavePath As String)
  62.         Try
  63.             Dim sqlQueryText As String = _
  64.               "BULK INSERT dialerresults " + _
  65.               "FROM '" & SavePath & "' " + _
  66.               "WITH ( FIELDTERMINATOR = ',' , ROWTERMINATOR = '\n' )"
  67.  
  68.  
  69.             ' and bulk import the data:   
  70.             'If ConfigurationManager.ConnectionStrings("Dialerresults") IsNot Nothing Then
  71.             'Dim connection As String = ConfigurationManager.ConnectionStrings("Dialerresults").ConnectionString
  72.             Dim connection As String = "data source=10.2.1.40;initial catalog=IVRDialer;uid=xxxx;password=xxxxx;"
  73.  
  74.             'I removed the DataTable declaration because you're not using it.
  75.             Using con As New SqlConnection(connection)
  76.                 con.Open()
  77.                 ' execute the bulk import   
  78.                 Using cmd As New SqlCommand(sqlQueryText, con)
  79.  
  80.                     cmd.ExecuteNonQuery()
  81.  
  82.                 End Using
  83.             End Using
  84.  
  85.             'Else
  86.             'message.Text="ConfigurationManager.ConnectionStrings('Dialerresults') is Nothing!"
  87.             'End If
  88.         Catch ex As Exception
  89.             message.Text = ex.Message
  90.  
  91.         End Try
  92.     End Sub
  93.  
  94. End Class
  95.  
And mechanically it works but when I submit the following data to it:

,512 406 1639,david thompson,doctor smith,20100501 12:45,20100501 12:45,,
,512 408 1323,steve miller,doctor stevens,20100709 1:30,20100709 1:30,,

it's double posted to my database. There is a clrf at the end of the data, so I don't think that's the issue. Does anyone have an idea why my page is "double posting" my information?

Thank you

Doug
May 19 '10 #1
2 1620
dougancil
347 100+
This was the problem:

Handles Submit1.Click

I've removed this handler and it works fine now.
May 19 '10 #2
ThatThatGuy
449 Expert 256MB
@dougancil
Glad you solved the problem on your own....
May 20 '10 #3

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

Similar topics

10
by: Manny | last post by:
I have a web form "Page1.asp" and it reads data from a database, does some calculations, and displays the records in pages. Works fine. I have a button that displays on the page, defined as...
1
by: G4Gun | last post by:
Hi, I have a form in which I have this link :- < href="javascript:submitform(parameters );"> . In the JavaScript function submitform, there is the code for submitting the form.Thi works fine with...
3
by: rufus | last post by:
Up until now I have been using OR Mapping tools for my database access. I liked this approach because with one line of code I could bind my form fields to my objects and then persist them. The...
5
by: Kevin C | last post by:
I was curious to know what some developers out in the industry are doing when it comes to exposing Data access logic, specifically persistence. This is assuming that your not using an O/R framework...
1
by: Patrick Olurotimi Ige | last post by:
Can anybody tell me what i'm doing wrong? The data is inserting 2 records at a time!!! Thanks Dim conn As SqlConnection Dim cmdcommand As SqlCommand Dim param As SqlParameter Sub...
4
by: Schwarty | last post by:
I hope I posted this to the correct group. If not, please let me know and I will get it posted in the correct section. I have a web application developed in ASP.NET using C# for the code behind....
1
by: Patrick | last post by:
Hi All, Can someone take a look at my script and tell me if I am missing something as to why the last line of data from my input file is being written twice in the echo. I have included a short...
23
by: Bjorn | last post by:
Hi. Every time i post data in a form the contents are being checked for validity. When i click the back-button, all data is gone and i have to retype it. It's obvious that only a few or none of...
18
by: NavinM | last post by:
I have a couple of forms that are misbehaving in FireFox, but work fine in IE. when i do submit( with submit button) a javascript function validates all of the fields entered, and stops the...
3
by: Thirdworld | last post by:
I'm building my first database and I'm having trouble using data as a reference on different forms. Is there any way that data submitted by one form could be used immediately as a reference for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.