I created code for converting binary data to pdf my aim is to show error message when date is not avalable in sql otherwise it should pdf file can anyone help me how to do.
Private Sub btnIn_Click(sender As Object, e As EventArgs) Handles btnInvoice.Click
Dim Date = txtDate.Text
Dim pdf As Byte()
Dim ID As String
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand()
cmd.CommandText = "SELECT Id, BinaryData FROM dbo.Reports WHERE date=@Date "
cmd.Parameters.AddWithValue("@Date ", Date)
cmd.Connection = con
con.Open()
Using sdr As SqlDataReader = cmd.ExecuteReader()
if sdr.hasrows then
sdr.Read()
pdf = DirectCast(sdr("BinaryData"), Byte())
ID = sdr("RunId").ToString()
else
messagebox("records not found")
end if
End Using
con.Close()
End Using
End Using
Response.Clear()
Response.ContentType = "application/pdf"
Response.AppendHeader("Content-Disposition", Convert.ToString("attachment; filename=Report.pdf"))
Response.BufferOutput = True
'Response.AddHeader("Content-Length", Response.Length.ToString())
Response.BinaryWrite(pdf)
Response.[End]()
End Sub