简体   繁体   中英

Unable to display image from database onto Crystal Report in C# Windows Form Appliction

As the question suggest, I m having the hardest of times displaying an image (varbinary(max)) on to a crystal report. I have read many similar questions and other links including this one below http://www.hexcentral.com/articles/crystal-images.htm

Which states that all I have to do is drag the image field to the report. Doing this has proven fruitless.

 SqlDataReader objReaderDetails;
        string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        using (SqlConnection conn = new SqlConnection(connectionString))
        using (SqlCommand cmd = conn.CreateCommand())
        {


            conn.Open();                 
            cmd.CommandText = "dbo.usp_print";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@applicationId", ID);  

            cmd.ExecuteNonQuery();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable ds = new DataTable();


            da.Fill(ds);

This is all the code i have, basically just creating a data source for the report. I have tried changing the data type, trying to modify my app.config but nothing helps.

I see simliar code posted but im hoping I get an answer to my issue.

Regards

Did you added Crystal Report Image handler to webconfig file?

This is the most important part and without it you will not see the Images in Crystal Report. You need to add the following in the section of Web.Config.

<add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />

For windows application ,use image data type to store image at sql server. attach table data to crystal report.

private void button2_Click(object sender, EventArgs e)
    {
        string str = "select photo from tbl_img where id='" + textBox2.Text + "'";

        string ConStr = @"Server=COMP7;Database=ImageTest;User Id=sa;Password=cos123";

        SqlConnection con = new SqlConnection(ConStr); 

        con.Open();
        SqlDataAdapter da = new SqlDataAdapter(str, con);
        DataTable dt = new DataTable();

        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            byte[] imgdata = new byte[0];
            imgdata = (byte[])dt.Rows[0][0];
            MemoryStream ms = new MemoryStream(imgdata);
            pictureBox2.Image = Image.FromStream(ms);      
        }
        else
        {
            MessageBox.Show("No images in a table");
        }
    }

Drag your image field on crystal report from Field Explorer->DataBase Field->Table Name->column Name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM