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()

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.