Hi, I have been working on this for over two weeks and its not working. I don't know what else to do since I'm really green at this. I'm trying to display binary data from a database using Response.Write(). Please take a look to see where I went wrong, thank you in advance for your help.
Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim DBConn As OdbcConnection
Dim DBCommand As OdbcCommand
Dim DS As New DataSet
If Not LBoxProfessions.SelectedItem Is Nothing Then
DBConn = New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=myDB;Database=myDB;User=myUserassword=myPW;Option=3;")
DBCommand = New OdbcCommand("Select ResumeID,Resumes,DocType from tb_content where Professions = '" & LBoxProfessions.SelectedItem.Text & "' Limit 10 Offset 10", DBConn)
DBConn.Open()
Dim AD As OdbcDataReader = DBCOmmand.ExecuteReader()
If (AD.Read()) Then
Dim contentLength As Integer = Convert.ToInt32(AD.GetBytes(0, 0, Nothing, 0, Integer.MaxValue))
Dim buffer As Byte() = New Byte(contentLength - 1) {}
AD.GetBytes(0, 0, buffer, 0, contentLength)
'Resumes is the field in the database table that holds the documents
Response.AddHeader("Content-Disposition", "attachment;filename=Resumes")
'DocType is the field that holds the mime types
Response.ContentType = DirectCast(AD("DocType"), String)
Response.BinaryWrite(buffer)
Response.End()
End If
DBConn.Close()
End If
End Sub