Monday, April 16, 2012

How to create a crystal report based on a custom SQL statement

Welcome everybody

In this article i will show you how to create a crystal report that based on a custom SQL statement; you have to follow these steps after creating a new project and a sample database :


  1. Add a data set item.
  2. Customize the data set to fit the data that will be retrieved from the database. 
  3. Add a crystal reports item and link it to the previous added data set.
  4. Add a crystal report viewer component to the form which you want to view the report and link it to the previous added crystal report.
  5. Find a way to program a function that returns a data table, and be sure that the columns names and the columns data types in the data table are same as these in the data set .
  6. Bind the data table with the data set, and the crystal report viewer with a report document by using this code
            ReportDocument rpt = new ReportDocument();
            DataSet1 ds = new DataSet1();
            ds.Tables[0].Merge(datattable1);
            rpt.Load(/*CrystalReport1.rpt path*/);
            rpt.SetDataSource(ds);
            crystalReportViewer1.ReportSource = rpt;

note: put the previous code in form load region.

And for more details watch this video

good luck

Tuesday, April 3, 2012

Simple Compiler in C# [source code]


This is a simple compiler programmed in C# that accept arithmetic operations with integers, "/", "^" and parenthesis symbols.

The project passes through three phases:
  1. Scanning phase: this stage check the code from syntax errors and unacceptable symbols
  2. Parsing phase: this stage do the semantic rules over the code and detect logical errors, rules are steted in parsing table.
  3. Evaluating phase: after two previous phases are checked and completed successfully the evaluating process complete its work and return the result.

Sample snapshots



Download the source code

Monday, April 2, 2012

How To Retrieve an image SQL Server Data type into Picture Box Using C#

Note: Before reading this blog,  you need to know (How To Store an Image to image SQL Server Data type Using C#)

Images are stored in SQL Server database as series of bytes; to retrieve an image into Picture Box follow these steps

1- Crete a stored procedure that do select command on an image
2- In C# code get the array byte retrieved from the database and convert it to Image 
        
        public static Image byteArrayToImage(byte[] byteArrayIn)
        {
            MemoryStream ms = new MemoryStream(byteArrayIn);
            Image returnImage = Image.FromStream(ms);
            return returnImage;
        }


3- Set the converted image to the picture box 


For more details watch this video







and download the source code for experiment purposes