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...