I created asp.net application.It save username,password,imagename and image path. but problem is click in to save button data save is twice.
this is my code
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
If FileUpload1.PostedFile IsNot Nothing Then
Dim FileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
Dim txt1 As String = Me.TextBox1.Text
Dim txt2 As String = Me.TextBox2.Text
'Save files to disk
FileUpload1.SaveAs(Server.MapPath("images/" & FileName))
'Add Entry to DataBase
Dim strConnString As [String] = System.Configuration.ConfigurationManager.ConnectionStrings("conString").ConnectionString()
Dim con As New SqlConnection(strConnString)
Dim strQuery As String = "insert into log (username, password,image,imagepath)" + " values(@Username,@Password,@ImageName, @ImagePath)"
Dim cmd As New SqlCommand(strQuery)
cmd.Parameters.AddWithValue("@Username", txt1)
cmd.Parameters.AddWithValue("@Password", txt2)
cmd.Parameters.AddWithValue("@ImageName", FileName)
cmd.Parameters.AddWithValue("@ImagePath", "images/" + FileName)
cmd.CommandType = Data.CommandType.Text
cmd.Connection = con
Try
con.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Response.Write(ex.Message)
Finally
con.Close()
End Try
End If
End Sub
Please help me that matter.
Rathnayake