Crystal Report with .Net – 2

April 24, 2010 at 7:21 am | Posted in Crystal Report | 1 Comment

Introduction

We have started to learn Crystal Report with .Net simple application now we are going for one more step that is connection with database. We need to have SQL server database with specific Table and Stored Procedure, I m guessing you are aware of this all. We need Stored Procedure for selecting record from particular table. To make information of report dynamic we are taking data from where that are being updating regularly. Following image is just give idea how application is interacting with database and report. We have to call data base from application i.e. code file and loads report with the help of dataset.

 

 

 

Let’s start build application for Crystal Report

We have Database: test, Tables: profile, Vehcle, Stored Procedures: getprofile,
getVehcle.

  1. Crete new website.
  2. Add Asp.Net folder App_Code folder
  3. Add new item profile.xsd in App_code folder
  4. Open profile.xsd right click on page and Add TableAdapter

  1. When you click on TableAdapter option you will be ask about connection string and databse information and click on Next >

  1. When u click next u will get following screen, we can select any of the option as requirement but we have already Stored Procedure so select third option and press Next >

     

     

  2. By clicking Next on from previous one you will get following select your procedure and press Next

     

     

  3. Choose methods to generate screen as follow, select next

  1. Now you will get final screen of Wizard result

     

     

And as you click on finish you will get TableAdapter with ‘getprofile’ name and also u can add any TableAdapter

 

Now your data set is ready to use. Now add new report file to the solution and give in database source this dataset

  1. Create new report file
  2. You can use formatting report but we have taken here with blank report
  3. From Field explorer right click on Database Fields > Database Expert > Create new connection > ADO.NET > give path of Dataset which we created earlier. > you will get following screen

     

     

     

  4. Select Data Adapter which you want to list and press ok
  5. Database fields > Drag and drop fields want to print on report.
  6. Report file is ready to use.

     

Now we are going to use both Dataset and report file. Following is process to use that files. Drag and drop report viewer tool to the .aspx file. Bellow code is written in page load event and we have use .vb as language.

Application code file .vb and .cs will have connection string connection string is:

Dim conn As
New System.Data.SqlClient.SqlConnection(“testConnectionString”))

We will use procedures to fetch data from database as in SqlCommand object:

Dim cmd As
New System.Data.SqlClient.SqlCommand(“getprofile”, conn)

cmd.CommandType = Data.CommandType.StoredProcedure

Dim cmdVehi As
New System.Data.SqlClient.SqlCommand(“getVehcle”, conn)

cmdVehi.CommandType = Data.CommandType.StoredProcedure

 

Load command in data table:

Dim xTable As
New System.Data.DataTable()

Dim xTblProgram As
New System.Data.DataTable()

Dim rdr As System.Data.SqlClient.SqlDataReader

 

conn.Open()

 

rdr = cmd.ExecuteReader()

xTable.Load(rdr)

rdr = cmdVehi.ExecuteReader()

xTblProgram.Load(rdr)

 

conn.Close()

 

Create object of dataset which we create earlier as we have given name that as ‘profile’:

Dim xsdName As
New profile

Call dataset methods:

For
Each dr As System.Data.DataRow In xTable.Rows

xsdName.getProfile.AddgetProfileRow(Convert.ToInt32(dr(“nameid”)), _

dr(“username”).ToString(), dr(“name”).ToString())

Next

 

For
Each dr As System.Data.DataRow In xTblProgram.Rows

xsdName.getVehcle.AddgetVehcleRow(Convert.ToInt32(dr(“vhid”)), _

dr(“vahicle”).ToString(), dr(“username”).ToString())

Next

Create object of Report document load report and give data source as dataset object:

Dim rptDocument As
New ReportDocument()

rptDocument.Load(Server.MapPath(“crProfile.rpt”))

rptDocument.SetDataSource(xsdName)

Now give data set object as source to report viewer tool and bind it.

crvNames.ReportSource = rptDocument

crvNames.DataBind()

 

Now enjoy Report if you finding any difficulty please give comment.

Crystal Report with .Net

April 20, 2010 at 11:15 am | Posted in Crystal Report | 1 Comment

Crystal Report is a reporting tool for generating report for the application. Here we will learn step by step.

In first we will create just simple report with current date

Create new website with Ajax-enabled, right now only default.aspx, default.aspx.vb, and web.config, here I have taken VB as language. This is first application so we will go in just depth of it.

 

Now drag and drop crystal report viewer from tool box to the page

 

Open CrystalReportViewer Task from triangle squared in image bellow. By clicking that you can get popup of CrystalReportViewer Tasks and from that you can chose report source. We are creating report first time so select option <New report source> rounded in following image.

  1. Open CrystalReportViever Tasks
  2. Creating new report source

 

By selecting that option you will get following screen. If report is already created then clicks on <Browse…> else select <new report…>. Again we are creating first report then select <New report…>

Then you will get following screen select option As a Blank Report option for blank report.

 

When u click OK button then u will get new blank report will be added to your solution and will be open. There is field explorer from where u can drag date to report.

1

 

2

 

After finishing this one you can see in your .aspx page some code will be as following. There will be to different tags one is for report viewing and other is for source of report

 

Now just run your application you will get current date as following

This is just first application for starting of learning Crystal report for them who are just beginners.

.Net Framework and Architecture

January 20, 2010 at 6:36 am | Posted in .Net Framework | Leave a comment

To develop, deploy and run application like Web, Desktop and Web service in a same platform, such infrastructure is provided is by Microsoft with a power full framework, is a well reach of class and architecture is .Net Framework.

  • .Net frame work provides a platform to develop application in a single roof with different languages.
  • It is allow multiple language develop with cross language integration
  • IT has IDE (Integrated Development Environment).
  • Framework is a set of utilities or can say building blocks of your application system.
  • .NET Framework provides GUI in a GUI manner.
  • .NET is a platform independent but with help of Mono Compilation System (MCS). MCS is a middle level interface.
  • .NET Framework provides interoperability between languages i.e. Common Type System (CTS) .
  • .NET Framework also includes the .NET Common Language Runtime (CLR), which is responsible for maintaining the execution of all applications developed using the .NET library.
  • .Net Framework consists primarily of a gigantic library of code.

Third Party Cookies and iFrame

January 12, 2010 at 1:31 pm | Posted in iFrame | 6 Comments

I came across a strange problem; I had done application with iFrame, as it is iFrame contains a source for other URI at that time mainly IE, which follows securities policy for third party, IE blocks this third party cookies and preventing data. For that I surf stuff but I find thing only P3P(Platform for Privacy Preferences) policies by W3C. this is really a boring thing to read.

Then I found a very short and sweet way to do this, by applying it into page starting u can get out of stuck:

PHP:

header(‘P3P:CP=”IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT”‘);

ASP.NET:

HttpContext.Current.Response.AddHeader(“p3p”,”CP=\”IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\”");

Django:

response = render_to_response(‘mytemplate.html’)

response["P3P"] = ‘CP=”IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT”‘

JSP:

response.addHeader(“P3P”,”CP=\”IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\”")

 

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.

Follow

Get every new post delivered to your Inbox.