Click here to Skip to main content
15,885,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

My problem is when I click on btnupload then, two times data is stored in table.
My code is:

VB
Protected Sub btnupload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnupload.Click
    imagename = imgupload.FileName
    fileExt = System.IO.Path.GetExtension(imgupload.FileName).ToLower
    If (fileExt = ".jpg" Or fileExt = ".gif" Or fileExt = ".bmp" Or fileExt = ".jpeg" Or fileExt = ".png") Then
        Label1.Visible = True
        imgupload.SaveAs(Server.MapPath("~/Images/" + imagename))
        Label1.Text = imagename + " is uploaded sucessfully"
        ipath = ("Images")
        'u.insertImgData(ipath, imagename, fileExt)
        Call save()
        Dim displaypath As String = "~/Images/" + imagename
        uploadedimg.ImageUrl = displaypath
    Else
        Label1.Visible = True
        Label1.Text = "Invalid extension"
    End If
End Sub

Private Sub save()
    con.Close()
    Dim ss As String
    con.Open()
    ss = "insert into imgData values('" & ipath & "','" & imagename & "','" & fileExt & "')"
    cmd = New SqlCommand(ss, con)
    cmd.ExecuteNonQuery()
    con.Close()
End Sub
Posted
Updated 21-Sep-11 23:16pm
v4
Comments
Sunasara Imdadhusen 22-Sep-11 4:57am    
did you checked you code is executed two times? put break point on btnupload_Click and let me know.
[no name] 22-Sep-11 5:09am    
i cant understand what you want to say.


  • Put break point on following function
    VB
    Private Sub save()
  • clear all entries from table
  • Run application
  • upload file and then click on submit button check
  • check following query on sql server query analyzer
    SQL
    count(*) from imgData
  • execute each lines and fire above query in database and check cause for that
 
Share this answer
 
v2
That implies that you may have two handlers (or the same handler added in two different places) defined to handle the click event - I'd check that first if I was you.
 
Share this answer
 
Your Not Executing the code two times please check it...... and run the appliaction.You should create one autoid function.for storing the data in database.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900