Passing SQL to Crystal Reports 10 using C# express and SQL Server 2005

Tools used in this example:
1. C# Express 2008
2. MS SQL Server Express 2005
3. Crystal Reports 10

I. Create the Report File
1. Click on File->New and select "As blank report" (The Database Expert wizard shows)
2. Expand the "Create New Connection" folder, and expand OLE DB (ADO). A window will appear.

3. On the Provider section, look for SQL Native Client. Select it and click Next.
4. On the Data Source combo box, type in the name of your server. (Mine is RIXX\SQLExpress)
5. Select the Integrated Security checkbox so that it uses your windows account for authentication.
6. Choose your database from the Database combo box and click finish. I have a database with the following attributes:
Name: TestDB1
Columns: Id, Description
Id Description
1 aaa
2 bbb
3 ccc
4 ddd
5 eee

7. Add your tables to the Selected Tables section and click Ok.
8. Drag the fields to the Details section of the report. Save your report. I used Report1.rpt.

II. Making the C# Project:
1. Create a new Windows application project.
2. Right click on the Toolbox and choose "Choose Items..."
3. Select the COM components tab.
4. Select the "Crystal ActiveX Report Viewer Control 10.0"
5. Click Ok. (The Crystal Report Viewer Control icon should now be visible on the toolbox.

6. Add a Crystal Report Viewer to the form.
7. Right Click on the Solutions Explorer and click Add Reference.
8. Click the Browse tab.
9. select the following location (or depending on where you installed your crystal report): "c:\Program Files\Common Files\Crystal Decisions\2.5\bin\" and select "CRAXDRT.dll"
10. Click Ok
11. Use the following lines of code when opening a report:

CRAXDRT.Report rpt = new CRAXDRT.Report();
CRAXDRT.Application app = new CRAXDRT.Application();
rpt = app.OpenReport("", null);
axCrystalActiveXReportViewer1.ReportSource = rpt;

12. the report viewer should then show the report you have created.

III. Passing SQL statements to the report.
1. Modify the code above into:
CRAXDRT.Report rpt = new CRAXDRT.Report();
CRAXDRT.Application app = new CRAXDRT.Application();
@"RIXX\SQLExpress", "TestDB1", "", "", null, @"Provider=SQLNCLI;Server=localhost;Database=TestDB1;Trusted_Connection=yes;"); //This is used for logging in to your SQL Server
rpt = app.OpenReport("d:\\report1.rpt", null);
rpt.SQLQueryString = "select * from TestTable1 where Id=4"; //instead of displaying all 5 records, I chose to display only the one with Id # 4.
axCrystalActiveXReportViewer1.ReportSource = rpt;

Create a Hello World application in C#

I assume that readers of this post are new to C# and have basic knowledge in programming and software application installation in Windows.

  1. Download the C# Integrated Development Environment (IDE) (You can download the free express version)
  2. After downloading the IDE, install it.
  3. The latest version of the C# IDE as of this writing is the C# express 2008 version.
  4. On the upper left corner, you can find a window-like box. Click on "Project..." next to the "Create" label. The following window will appear:
  5. the default project name is WindowsFormsApplication1. Change it to your desired project name.
  6. After clicking the Ok button, the following should appear:
  7. Program.cs is the main program file which calls the Form1.cs so that when you run the application, the form appears firsthand.
  8. On the Toolbox tab at the left side of the IDE, drag and drop a "Label" control to the form.
  9. The "Label" control has its own properties which can be accessed from the lower right portion of the IDE. Look for the property labeled with "Text" and change its value with "Hello World".
  10. Run the program by pressing F5. You now have created a Hello World application.

What's new in my online life?

Got invited by one of my students to Ciao.It's a community site that is intended for the world's consumers (various products). What's interesting is that the site pays for your reviews from computer peripherals to kitchen appliances buying guide. Not only do they pay for reviews, they also pay for the comments you put on other users' reviews. Cool right? Well, if you're asking if they really pay or not, I cannot answer that yet as I have only made $4.21 as of today. They only allow payment requests when you reach $5. It's just a matter of time before I reach that amount and I verify if they really pay or not. I will be posting the results here. As far as I've heard, the site is really legit. Well, you'll never know unless you try. If you decide to join, then add me up. My user name is fiShBoN3.

Crazy over the macbook cam

Just another dull moment. Decided to take some pictures and a video from my colleagues macbook.

Abort shutdown

Sometimes we encounter something like a dialog box popping out of our computer screen saying that our computer is shutting down and we didn't even initiate it. Sometimes it's a result of an updater, a trojan, or a remote shutdown. It can actually be aborted.

Just click Start->Run and type shutdown -a.

Simple Inheritance in PHP

In object-oriented programming, inheritance means that a new class can be derived from an existing class. The concept is easily implemented in object-oriented languages such as Java or C#. Inheritance can also be implemented in php. The method is quite straightforward: Use the extends keyword. The following example is a simple implementation of the concept:

In the following example, I have 3 files: Person.class, Student.class, and TestStudent.php. The Person.class has the following attributes: Last name, First name, and Middle name. It has one display method that returns an html code that displays the attributes of the person. The Student.class inherits the Person.class and also has its own attributes: Id, Year/Level, and Course. The TestStudent.php tests the Student class by asking for inputs of all six attributes using only the Student class and displays all of them in tabular form.


class Person{
var $LastName="";
var $FirstName="";
var $MiddleName="";

//Set/Get methods *********************************
function SetLastName($LastName){
$this->LastName = $LastName;
function GetLastName(){
return $this->LastName;

function SetFirstName($FirstName){
$this->FirstName = $FirstName;
function GetFirstName(){
return $this->FirstName;

function SetMiddleName($MiddleName){
$this->MiddleName = $MiddleName;
function GetMiddleName(){
return $this->MiddleName;

function DisplayPerson(){
"<table border=1 cellpadding=1>".
"<tr>"."<td>first name</td>"."<td>middle name</td>"."<td>last name</td></tr><tr>".
return $content;




Class Student extends Person{
var $Id;
var $YearLevel;
var $Course;

//Set/Get methods *********************************
function SetId($Id){
$this->Id = $Id;
function GetId(){
return $this->Id;

function SetYearLevel($YearLevel){
$this->YearLevel = $YearLevel;
function GetYearLevel(){
return $this->YearLevel;

function SetCourse($Course){
$this->Course = $Course;
function GetCourse(){
return $this->Course;

function DisplayStudent(){
$content = $this->DisplayPerson().
"<table border=1 cellpadding=1>".
"<tr>"."<td>Id</td>"."<td>Year Level</td>"."<td>Course</td></tr><tr>".
return $content;





<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">


<title>Sans Titre</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="generator" content="HAPedit 3.1">
<body bgcolor="#FFFFFF">

<form name="myform" method="post" action="<?php echo $_SERVER["PHP_SELF"] ?>" >
<td>First Name:</td>
<td><input type="text" name="FirstName" /> </td>
<td>Middle Name:</td>
<td><input type="text" name="MiddleName" /></td>
<td>Last Name:</td>
<td><input type="text" name="LastName" /> </td>
<td><input type="text" name="Id" /></td>
<td><input type="text" name="Year" /></td>
<td><input type="text" name="Course" /></td>
<td> </td>
<td align="right"><input type="submit" name="Go" value="Go" /></td>
<br /> <br />

$s = new Student();

echo $s->DisplayStudent();



Using MS SQL Server express with C# express

I think I missed this one out. Many of us connect to Microsoft's SQL Server database using controls. I don't usually use this technique because it is quite limiting for me. Here's how to connect to MSSQL Server 2005 database using C#:

1. First, create a database (I'm using MS SQL Server 2005 express edition, so I use the SQL Server Management Studio IDE which can be downloaded here.)

2. To proceed, I'm assuming that you can already connect to your server (or the instance thereof). If the Windows Authentication doesn't work, you might want to try the user 'sa'. The password actually depends on what you specified during its installation.

3. Right click on the "Databases" folder and click "New Database".
(Just leave everything default and click ok).

4. Expand the newly created database folder (in my case, it's testDB1), and create a new table with the following attributes:
Table Name: TestTable1
Id:Integer, auto increment, pk
Description: varchar(50)

(I won't go on the details on creating this table).

5. Populate your table. Mine has the following data:
Id Description
1 aaa
2 bbb
3 ccc
4 ddd
5 eee

6. Now we go to the C# express IDE. I'll be using C# express 2008. (I named my project "ConnectToSQLServer").
7. Add a DataGridView control to the form.
8. Go to the code view of your form.
9. On the upper part of the code where you can find the "using" statements, add the following:
using System.Data.OleDb;

10. Add the following code to the constructor (modify the connection string to fit your setting. In my case, the SQL server is Rixx\SQLExpress. I'm using the trusted connection since I'm using Windows Authentication for my access level):
OleDbConnection cn = new OleDbConnection(@"Provider=SQLNCLI;Server=RIXX\SQLExpress;Database=testDB1;Trusted_Connection=yes;");
OleDbDataAdapter da = new OleDbDataAdapter("select * from testTable1", cn);
DataTable dt = new DataTable();
dataGridView1.DataSource = dt;

11. run the program. The data from your database should be shown.

The codes will look like this:

Mac's camera

It's kinda funny.


Apparently, I think this blog has become supplemental (or so I think). I think the algo is playing with me. geez. I need to read more. It's just been 72 hours and it dropped again. I'm waiting for the next crawl. It should go back up. Hmmm... hopefully by Nov. 25, 2008.

Page Rank Recovered

Two months ago, my page rank dropped to 2 from 3. Last month, it became N/A and I was shocked. I thought I did a violation that got me banned from Google. Well, some of my assumptions were wrong. I managed to recover my page rank back to PR 2. I hope I manage to get it back to PR 3 in time. I need to do something with a PR 3 blog hehehe. What I did was to redesign the blogsite and tried to optimize the tags, a lot of directory submissions, and most importantly, add content. There should be continuous updates with the blog. A CSS validator helps, so does the HTML validator. Various SEO tools also help. I use the WebCEO free version. Want to check the page rank of your site? Use the tool below:

Check Page Rank of any web site pages instantly:

This free page rank checking tool is powered by Page Rank Checker service

How to cheat blog polls

Ok, I really need to post this. Many bloggers put polls on their blog sites and rely heavily on the results that they give and some even draw conclusions based on those data. The problem is that they don't check where the data those polls are generating are stored. Many polls don't even record the voter's information. Well to those of you who want to cheat polls (I mean blog polls. Some polls are really reliable), here are some points:

1. These polls don't store your IP address nor your MAC address, how then do you think are they checking for flying voters? COOKIES!
2. Now you already have an idea. Now try to vote to a blogger's poll then clear your cookies and refresh the page. You'll be able to vote again.
3. If #2 doesn't work, there's a big chance that your voting data is stored on internet temporary files. Now you know what to do. Delete those files.
4. If #3 doesn't work, then your data might have been stored elsewhere. You might want to use a different PC.
5. If #4 doesn't work, try a proxyfier.
6. If #5 doesn't work, ask yourself this question: Why do I need to cheat the poll?