Hi phonghue,
After insert is executed you can redirect to the same page.
Response.Redirect(Request.Url.AbsoluteUri);
Use this code and check.
Protected Sub Upload(ByVal sender As Object, ByVal e As EventArgs)
Dim filename As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
Dim extension As String = Path.GetExtension(filename)
Dim contentType As String = FileUpload1.PostedFile.ContentType
' Check file extension.
If extension.ToLower() = ".pdf" Then
Using fs As Stream = FileUpload1.PostedFile.InputStream
Using br As BinaryReader = New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(Convert.ToInt32(fs.Length))
Dim connString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using conn As SqlConnection = New SqlConnection(connString)
Dim query As String = "INSERT INTO tblFiles (Name, Contenttype, data) VALUES (@Name, @ContentType, @Data)"
Using cmd As SqlCommand = New SqlCommand(query)
cmd.Connection = conn
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = filename
cmd.Parameters.Add("@ContentType", SqlDbType.VarChar).Value = contentType
cmd.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
End Using
End Using
End Using
End Using
lblMessage.Text = "File uploaded successfully."
lblMessage.ForeColor = Color.Green
Else
lblMessage.Text = "Select only pdf file."
lblMessage.ForeColor = Color.Red
End If
Response.Redirect(Request.Url.AbsoluteUri)
End Sub