Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Tuesday, 26 September 2017

Read PDF document from database ~ gniithelp ~ programming info

Part of code that I use for reading a PDF document from database into Internet explorer.
We first need one asp.net page with link . When we click on it we do Response.Redirect() to this page and send a parameter ID which we read in Page Load and use it to do simple sql query which will read a PDF data stored in it . (We store PDF as Byte array in data table column) . 
This time I will not post all the detail about it, if someone need more info let's message me and I will try to show more about these simple task :) 

Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load
If Request.QueryString("id"IsNot Nothing Then
Dim ImageID As Integer = Convert.ToInt32(Request.Params("id"))
Dim strConnString2 As String = System.Configuration.ConfigurationManager.ConnectionStrings("conString").ConnectionString()
Dim con2 As New Data.SqlClient.SqlConnection(strConnString2)
Dim command2 As SqlCommand = New SqlCommand("procKOP_DokumentiSelect", con2)
command2.CommandType = CommandType.StoredProcedure
command2.Parameters.AddWithValue("@ZahtjevID", ImageID)
command2.Parameters.AddWithValue("@TipSelecta", 0)
con2.Open()
Dim reader As SqlDataReader = command2.ExecuteReader()
If reader.Read() Then
Response.ContentType = "application/pdf"
Response.BinaryWrite(DirectCast(reader("fldDokument"), [Byte]()))
End If
reader.Close()
con2.Close()
End If
End Sub
Read More »

Searching string in all Store procedures in database ~ gniithelp ~ programming info

I'll show you how to do search trough all SP in one database to find a sting , text .
It's very useful part of MS SQL code :



SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%user_name()%'
AND ROUTINE_TYPE='PROCEDURE'





select * from sysobjects o inner join syscomments c on o.id=c.id
where c.text like '%user_name()%'

Here you can see two simplest piece of Sql code that executes search trough all Store procedure in selected database for termin "user_name()" . It is very fast and useful .
Read More »