Friday, October 8, 2010

Working with Crystal Report and ASP.Net

How to create reports using Crystal Reports in ASP.Net?

Introduction
Integrating Crystal Reports with .Net can be a real challenge if you don't know number
of things required for it. I am going to explain you here those things with a very simple example.

Before explaining about implementing crystal report in ASP.Net, i assume you have the knowledge of following:
- ASP.Net 2.0
- C# or VB.Net [I will use C# for this tutorial, you can use VB.Net if you wish.]
- SQL Server 2005
- XML Schema

Now follow below simple steps to impletment crystal reports:
1) Create a Dataset DS which has all the data to be displayed in Report.
  • you can create dataset by fetching data from Database or by creating static dataset in your sample application.
2) Create an XML Schema definition.
  •   Add an XML Schema by Right Clicking your application -> Add New Item -> DataSet (.xsd File) and create all the tables in schema as per in the Dataset.
3) Add a crystal report viewer in your web form and call it crystalreportviewer1 for example.
4) Add a Crystal Report in your application and select "Using the Report Wizard" in the "Crystal Report Gallery" popup.

Crystal Reports Gallery


5) Now Standard Report Creation Wizard will be shown. 
Select Create New Connection -> ADO.Net -> Make New Connection(if displayed). It will display a Connection Popup.
   - Select  the XML Schema Definition we have created in the File Path and Finish.
   - Now it will display XSD name as a Connection and the Table names under it as per created in XSD. Select all the tables displayed under connection in the "Available DataSource" to the right side in "Selected tables".

Report Creation Wizard

- Now follow the wizard steps.
- select the fields to be displayed in the "Fields" Box. Click Next.
- if you need any grouping in your report, select the Group fields on which grouping will be applied.Click Next.
- if you need any Summary to be displayed in reports, select the summary fields.
- follow the report steps and finish.
6) Format your Crystal Report as per your requirement. You can add Group Section by Right Click in the Report -> Insert -> Group, if you have selected group fields in above steps.
7) Now Turn to your Web page in which you want to display report, where your code will be looked like below.

Declare 2 public variable for ReportDocument and Dataset of type created XSD.

ReportSchema dsschema = new ReportSchema();
ReportDocument rpt = new ReportDocument();

Now write down below code in your button click event where you want to display the report.

//Fetch data from the records dataset to the dataset object of type Schema
dsschema.Tables["Table1"].Load(ds.Tables["Table1"].CreateDataReader());
dsschema.Tables["Table2"].Load(ds.Tables["Table2"].CreateDataReader());

rpt.Load(Server.MapPath("Report.rpt"), OpenReportMethod.OpenReportByTempCopy);

CrystalReportViewer1.ReportSource = rpt;
//CrystalReportViewer1.RefreshReport();
CrystalReportViewer1.DataBind();

CrystalReportViewer1.DisplayGroupTree = false;
//Display the Toolbar in Crystal Report Viewer Control
CrystalReportViewer1.DisplayToolbar = true;
//Hide Business Objects Logo on Crystal Report Viewer Control
CrystalReportViewer1.HasCrystalLogo = false;

There you go...You are now ready to execute above script to display your crystal report.
if you have any query or concerns, then please write down a comment or mail me at shahbrijal@gmail.com

Friday, September 17, 2010

Configuring custom domain with Google Email Service

Most of the hosting companies do not provide email hosting along with domain registration.

So if you want to provide business email ids of type 'name@yourdomain.com' to all your employees for internal communication or external communication with clients, you also need to buy email hosting from some company along with registering domain name.

I am going to explain here the alternative of buying email hosting from some web hosting company, which could also save money for your organization in addition to provide you with some great services for free.

Google Apps is the service provided by google as part of providing email hosting services. Google Apps has different editions for the type of users and with specific collection of services for each editions.

For free service, you can choose standard edition, in which it provides upto 50 email accounts of type 'name@yourdomain.com' for free and other services like Google talk, Google calendar,Google Sites and Google Docs are provided in addition.

How to configure your custom domain name with Google Apps?

1. Sign Up for the Google Apps
2. Select your User Type and enter your domain name. if you don't have the domain, you can buy it from google and proceed.
3. Fill up the form provided and sign up.
4. Now go to DNS Management interface in control panel provided by your web hosting service provider, and you have to add/modify CNAME and MX records provided by Google.

There you are..!!! You are done with setting up Google Apps for your custom domain now.

You can create different users and groups and also restict and unrestrict them to use any of the services provided in Google Apps.

The main advantages of using Google App over other email hosting services are the free sevices it provides.

Note: You should wait for about 48 hours to propagate the changes you have made in DNS Management. So please have some patience.
 
If you still face any problem, feel free to contact me on shahbrijal@gmail.com or you can post your comment to this post.

Glad to help you guys..!!!

Thanks,

Wednesday, August 18, 2010

Export Excel File into Dataset

Sometimes it happens that you have substantial amount of data in an excel file and you need to fetch all the data into the database. it's a very labour task if you have to insert data into database manually one by one( just imagine what will happen if you have 1 million rows in an excel file.!!!!)

Below code snippet, written in C# language, will help you overcome these situation.

NOTE: This code snippet is written with consideration that the user has enough knowledge about ASP.Net, ADO.Net and Excel File



DataSet ExcelDataset = new DataSet();
string filePath = @"D:\TestData.xls";
string sConnectionString = string.Empty;
sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath +

           ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1;MAXSCANROWS=0\"";
    try
    {
         using (OleDbConnection ExcelConnection = new OleDbConnection(sConnectionString))
         {
                 ExcelConnection.Open();
                 using (OleDbDataAdapter ExcelDataAdapter = new OleDbDataAdapter("SELECT * FROM [Query$]", ExcelConnection))
                 {
                         ExcelDataAdapter.Fill(ExcelDataset);
                 }
         }
    }
    Catch(Exception e)
    {
         throw;
    } 
    finally
    {
    }

Explanation:
In above code snippet, i have used OleDBConnection and OleDBDataAdapter to connect and fetch data from excel file.

Let's understand the ConnectionString:
As you can observe, i have used Microsoft.Jet.OLEDB.4.0 as a Provider here. You can use this provider for excel files of Versions Excel 97 and Excel 2000, where as you can use Microsoft.ACE.OLEDB.12.0 as a provider for excel files of Excel 2003 and later versions.

The Datasource contains the physical location of the excel file you want to import.
Now the most important part of the connectionstring Extended Properties must be specified as Excel 8.0 or Excel 12.0 depending on the version of the MS Excel you are using.
HDR=Yes specifies that there is a header row in the cell range, so the provider will not include first row in the recordset.
IMEX=1 specifies the mixed datatypes are accepted as a TEXT in the cells.

Saturday, August 7, 2010

Google Adsense

If You own a site or blog or any online pages, it's easy for you to earn money online without doing anything but just displaying Google ads on your pages.

The obvious question arise in your mind is "why Google pay money for just displaying these ads?"

As you might know, Google earns most of its revenue from these advertises. The program that enable other websites to display their ads on Google is called "Google Adwords".

Now, using Google Adsense you're helping Google advertise and that's why they pay you a percentage of what they earn.

How Google benefits even if they share percentage of revenue with us?

That's the brilliance of Google.

Now, using these adsense program, the advertisers ads are being displaying on more websites then just Google's website alone, so they will get much traffic and even more clicks on these ads. And who would not like to fetch much traffic on their sites?

As more traffic advertisers receive, their advertising funds used up very quickly.
In Google Adwords, the advertisers gets charged every time the site gets a visit.And it's a general thinking that if you can make good business by increasing traffic on your site, you will keep adding funds for advertising (usual marketing strategy).

Now, you must have understood why Google share percentage of revenue with ad publishers.

How to configure Google Adsense for your website/blog?

There are few simple steps you need to follow to configure Google Adsense:

1. Login to Google Adsense using you Google Account. Don't have Google Account, Click here and then login to Google Adsense.

2. Now go to Adsense Setup tab and choose the type of Ad you want to publish on your website. You can customize the look and feel of ads.
3. At the end, you will get a HTML Code, that you have to put somewhere in your website where you want these ads to get displayed.
4. Now everytime someone clicks on these ads, you will earn a share of what Google earns.

Happy Google Adsensing...

Saturday, July 31, 2010

Why the title includes "Undiscovered"?

Hello everyone,

This is my first post on the blog, or you can say my first kind of writing which is being published ever.
As I had never been a good writer (not even now, i suppose, as even in IELTS score i have got 5.5 bands in writing..;-)), I had never thought of writing something and get it published.

So i was just thinking what made me start writing this blog or what inspired me to write something over here. Whatever is the reason but i have made up my mind now, so guys please bear me for this ;-).

So till now you guys might have understand why i have used this title.

I will use this blog to discover myself and share my knowledge starting from general issues to technical with you all.

Thanks,
BRIJAL