Pages

Saturday 25 October 2014

Crystal Report in windows form application

Overview : Crystal reports are best used for printing document. Crystal reports provide a great printing experience. In this article I will tell you about how to add crystal report to your application and it's working.

Initially for this we need to take a DataSet from Add New Item in our application, and after adding the dataset we need to create a DataTable in our DataSet. I am creating a table with the name DataTable2. After adding table add some columns in your table as per your requirements. I am adding these columns as shown.
   

Now we need to add a crystalreport to our application from Add New Item in Reporting section as follows : 

After adding Crystal Report, a window named Database Expert appears, in this window expand Project Data, then expand ADO.NET Dataset then expand your dataset which you have created earlier and finally select your table and press OK.

Now you will see five sections in your crystal report as 
1. Section 1 (Report Header) : This section will be printed on the first page of the report.
2. Section 2 (Page Header) : This section will appear in all printed pages of your report.
3. Section 3 (Details) : This section will be repeated according to your data in DataTable.
4. Section 4 (Report Footer) : This section will be repeated once in a report.
5. Section 5(Page Footer) : This section will appear in footer of every page.

After placing data at appropriate place, your report is ready for print command, Now we will see the code to print the report.

The below shown code will be placed on the Click command of the button on which the report will be printed : 

First of all we will declare a DataTable with same name as in DataSet as follows : 

                            DataTable DataTable2 = new DataTable();
                            DataTable2.Columns.Add("date", typeof(string));
                            DataTable2.Columns.Add("agent", typeof(string));
                            DataTable2.Columns.Add("amount", typeof(string));
                            DataTable2.Columns.Add("receivedby", typeof(string));

now populate the DataTable with data as follows : 


                            DataRow dr = DataTable2.NewRow();
                            dr[0] = "column1";
                            dr[1] = "column2";
                            dr[2] = "column3";
                            dr[3] = "column4";

                            DataTable2.Rows.Add(dr);

After this the print command :

crystalreport1 crr1 = new crystalreport1();
crr1.Database.Tables["DataTable2"].SetDataSource((DataTable)DataTable2);
crystalReportViewer1.ReportSource = crr1;

This code will print the crystal report to your default printer.

NameSpace for this action : 

using System.IO;
using System.Drawing.Printing;


Happy Coding....

Friday 24 October 2014

How to change SCHEMA name in SQL SERVER

  1. Description:
 A Database schema is a described structure in a language supported by DBMS.

Example:
USE databasename;
GO
ALTER SCHEMA new_schema TRANSFER old_schema.TableName;
GO

Sunday 19 October 2014

User control in ASP.NET

Usercontrols can be understood as a portion of web page created separately as some other page but can be called at any location withing a web page. The advantage of creating usercontrol in an application is that you need not to write the same code again and again.


Adding usercontrol to website :  
  

   Add usercontrol by simply adding new item to your site as shown in image : 
 


Adding usercontrol to a page : 

  To add a usercontrol to a page you need to write this code on top : 

<%@ Register src="~/usercontrol/mainheader.ascx" TagName="UserInformation" TagPrefix="UserInformation" %>

after adding the above code on top of the page, now you just need to place the code on the place you need to add the usercontrol

<UserInformation:UserInformation id="UserInformation" runat="server"/> 


As Simple As That