07 June, 2011

Image Type data in MsSQL Show in Crystal Report using C#

1. Add a data set in your project.
- add a data table in this data set.
- add column that you want to show your report.
- go to picture/image type data column properties.
- change data type to System.Byte[].




2. add a crystal report, go expert data source , show the data table.

- design your report... give the picture field...in your crystal report.
3. Add a form than add a crystal report viewer. then write the following code in form load section.

CrystalReport1 objRpt;
private void Form1_Load(object sender, EventArgs e)
{
   objRpt = new CrystalReport1();3
   string connString = "Server=ServerName;Database=DataBase;User
ID=UserID;Password=Password;";
   string query = "Write Your Query";
   using (SqlConnection Conn = new SqlConnection(connString))
   {
       SqlDataAdapter adepter = new SqlDataAdapter(query, connString);
       DataSet DS = new DataSet();
       DataTable DT = new DataTable("DataTable1");
      //DataTable name must mach with Step1 Data table
       adepter.Fill(DS);
       DT = DS.Tables[0];
       objRpt.SetDataSource(DT);
       crystalReportViewer1.ReportSource = objRpt;
   }
}


and then just run your project........and enjoy it!!!!!!!!!!!!!!!!!!!!!
If this post is help you.......comment please......................

1 comment: