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 »

Asp.Net prevent Button Click until long time Insert Query done ! ~ gniithelp ~ programming info

In this post you will see how to do some simple prevention on Asp.net page button click until long time inserting query done.

If you work a lot with SQL Store procedure, or other ways of T-SQL communication between your Asp.net page and database, it's so possible that you have to do some prevention when user try to insert or update some long data to SQL .

With this line of code when user make first click button become a disabled until inserting,updating done!.

protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(Button1, null) + ";"); // C#
}

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Button.Attributes.Add("onclick", " this.disabled = true; " &
ClientScript.GetPostBackEventReference(Button1, Nothing) & ";") // VB.NET
End Sub
Read More »

MSSQL : Update a column in one table with values from some other table ~ gniithelp ~ programming info

In this post I will show you one useful MS T-SQL Query.
It's about updating a one column from one tables with values from some other table.

The query :



UPDATE t1
SET t1.column1= t2.column2 FROM dbo.someTable1 t1 INNER JOIN
dbo.someTable2 t2 ON t1.joinColumn =t2.joinColumn

We do simple update a column in table someTable1 alias t1 with values from someTable2, we do inner join on join column in this sample that is a joinColumn .

That' all folk's for this time ;)
Read More »

Fast export of AspxGridView data to Excel ,PDF ,CSV ,RTF file type C#,VB.NET ~ gniithelp ~ programming info

Hi to all of you who came in this place searching some info about programming . In this blog post I will show you how to do very, I mean very fast export of Your data from AspxGridView to Excel spreadsheet ( or PDF or CSV or RTF file type ).
First of all in this post I will use DevExpress Asp.net controls toolkit (8.2.4). That's mean DevExpress toolkit is requirement.
You can find 60 days trial version on this link: http://www.devexpress.com/Downloads/
Let's start with show J
First we need to start our Visual Studio 2008 ( my favorite version, but this version of DevExpres controls works fine with VS2005 ).
As we start new Web Site Project template, we need to find our AspxGridView control on VS Toolbox and do simple drag & drop on our test page.
Next step ,we need to do simple connection between aspxgridview and sqldatasource, I hope you all know how to do that J.

After we successfully connect to our sqldatasource next step is to add one button from VS Toolbox of course with one fast andsimple drag & drop.

Let's change text property of our button. I will write ' Export to Excel', next step to do is one more drag & drop , now we will add most useful control that we need to make our task fast and efficient
That's AspxridiewExporter.

Only one thing we need to do with it and that is to connect AspGridViewExporter property 'GridViewID' with our AspxGridiew ID :
Next step is to make double click on our button and in his Click property write this magical command :

ASPxGridViewExporter1.WriteXlsToResponse(); // Case we use C#
Me.ASPxGridViewExporter1.WriteXlsToResponse() // or we use VB.NET
If we wish to export our AspxGridView data to some others file formats we only need to write this commands :ASPxGridViewExporter1.WriteCsvToResponse(); // for CSV file C#
ASPxGridViewExporter1.WritePdfToResponse(); // for PDF C#
ASPxGridViewExporter1.WriteRtfToResponse(); // for RTF C# Me.ASPxGridViewExporter1.WriteCsvToResponse() //for VB.NET Me.ASPxGridViewExporter1.WritePdfToResponse()
Me.ASPxGridViewExporter1.WriteRtfToResponse()
Last thing is to make run of our test site and do some simple Click on button ‘Export to Excel’ and if all goes right we will see ‘File Download ’ dialog with options Open, Save ,Cancel . We do Click on Open and we see Excel spreadsheet with our AspxGridViewcontent in it :P


The mission ‘Fast GridView export to Excel with DevExpress Asp.net controls ’ is successful.
That’s all for this post J
Read More »