0

I try to retrive the doc file from sqlserver,when i execute the code ask me
Do you want to open save file? when i click open button the doc file open with error "System.Byte[]"

Dim sql As String
Dim strcon As New Configsetting
Dim cnn As New OleDb.OleDbConnection(Configsetting.ConnectString)
Session("Req_SeCode") = e.Item.Cells(1).Text
cnn.Open()
sql = "Select Doc from mst_CandidateInfo where Can_Code=" & Session("Req_SeCode")

Dim cmd As New OleDb.OleDbCommand(sql, cnn)

Dim obj As Byte() = CType(cmd.ExecuteScalar(), Byte())
Response.ContentType = "Application/msword"
Response.BinaryWrite(CType(cmd.ExecuteScalar(), Byte()))
Response.[End]()
con.Close()

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Teme64
0

You execute SQL query twice:

Dim obj As Byte() = CType(cmd.ExecuteScalar(), Byte())
Response.ContentType = "Application/msword"
Response.BinaryWrite(CType(cmd.ExecuteScalar(), Byte()))

How is your Doc stored in DB? As an image-type field? You may try to change latter cmd.ExecuteScalar to:

Response.BinaryWrite(obj)

since obj should contain Doc-field as a byte array at that point.

You may also take a peek at how to save binary data to SQL Server with VB.NET. The code can be easily converted to retrieve binary data, just change INSERT to SELECT statement and parameter direction: ParameterDirection.Input -> ParameterDirection.Output

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.