Click here to Skip to main content
15,878,748 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Hi
My name is sudeshna. i want to display serial number product name and product image, cost price in my crystal report

The images getting stored in database.

I want to retrieve from database and display in crystal report.

I have done a lot of research from google, didn't find exact what i want.

So i will be obliged if any one can help me.

I went to solution explorer,then add item-> then clicked crystal report-> then standard report-> chose db->then tables-> then fields and then formatted the fields.

all data are coming in other fields except in image field, only name of the image coming

please let me know how to display image also in crystal report


Thanks
Sudeshna
Posted

1 solution

Use Image DataType to store Image in Sql Database
protected void SaveImage_Click(object sender, EventArgs e)
{
    if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
    {
        byte[] img = new byte[FileUpload1.PostedFile.ContentLength];
        HttpPostedFile Image = FileUpload1.PostedFile;
        Image.InputStream.Read(img, 0, (int)FileUpload1.PostedFile.ContentLength);
        string str = "insert img values(@img)";
        SqlConnection cn = new SqlConnection("data source=localhost;initial catalog=DBName;user id=sa;password=password");
        cn.Open();
        SqlCommand cmd = new SqlCommand(str, cn);
        cmd.Parameters.AddWithValue("@img", img);
        SqlDataReader dr = cmd.ExecuteReader();
        cn.Close();
    }
}


protected void ViewReport_Click(object sender, EventArgs e)
{
    SqlConnection cn = new SqlConnection("data source=localhost;initial catalog=DBName;user id=sa;password=password");
    cn.Open();
    SqlDataAdapter cmd = new SqlDataAdapter("select * from img", cn);
    DataTable dt = new DataTable();
    cmd.Fill(dt);
    string file = Server.MapPath("") + "\\CrystalReport.rpt";
    CrystalDecisions.CrystalReports.Engine.ReportDocument orpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
    orpt.Load(file);
    orpt.SetDataSource(dt);
    CrystalReportViewer1.ReportSource = orpt;
    //CrystalReportViewer1.DataBind();
}
 
Share this answer
 
v3
Comments
sudeshna from bangkok 11-Dec-14 3:14am    
i have taken image field in database as varchar(max) and how to attach table with crystal report?
Sid_Joshi 11-Dec-14 3:20am    
Dont Take varchar(max)
use
CREATE TABLE [dbo].[img](
[id] [int] IDENTITY(1,1) NOT NULL,
[photo] [image] NULL
)
Sid_Joshi 11-Dec-14 3:25am    
and Drag Photo field from Database Fields to Your Crystal Report.
sudeshna from bangkok 11-Dec-14 3:26am    
ok then i will create another new table right with table name img,right?
as i have 1 table already with fields serial number int
category varchar
image varchar(max)
costprice float
selling price float
Sid_Joshi 11-Dec-14 3:30am    
just change the data type of your image field
I just crearted img table for testing

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900