Firstly, you can make your whole life easier if you look at the File class - all of this code:
Dim fInfo As New FileInfo(TextBox1.Text)
Dim numBytes As Long = fInfo.Length
Dim fStream As New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read)
Dim br As New BinaryReader(fStream)
Dim data As Byte() = br.ReadBytes(CInt(numBytes))
br.Close()
fStream.Close()
can be done with a single line of code:
Dim data As Byte() = File.ReadAllBytes(TextBox1.Text)
Easier to write, easier to read.
Then, your problem: read the data from the DB:
Try
Using con As SqlConnection = New SqlConnection(strConnect)
con.Open()
Using cmd As SqlCommand = New SqlCommand("SELECT content FROM tbldocument WHERE filename = @FN", con)
cmd.Parameters.AddWithValue("@FN", filename)
Dim data As Byte() = CType(cmd.ExecuteScalar(), Byte())
...
End Using
End Using
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
You can also use the File class to write the file in a single line of code:
File.WriteAllBytes("D:\Test Data\TheFile.pdf", data)