Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Showing Picture in Crystal Reports from Table

Showing Picture in Crystal Reports from Table

Scheduled Pinned Locked Moved C#
databaseperformancehelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    M Riaz Bashir
    wrote on last edited by
    #1

    hi all I have uploaded a picture into table but i am stuck, that how may I show the picture in Crystal Reports from table. I used following codes to upload the picture it works fine

                // load the file that we want to upload into memory
                fileStream = new System.IO.FileStream(strFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                reader = new System.IO.BinaryReader(fileStream);
                data = reader.ReadBytes((int)fileStream.Length);
    
                // open the connection to the database
                //conn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AccessFile.Text);
                //conn.Open();
    
                // determine if the file already exists.  If the file does not already
                // exist, add the file to the table.
                cmd = new OleDbCommand();
                cmd.Connection = Module.objConnection;
                string strQuery = 
                    "SELECT \* FROM PICTURES WHERE " + 
                    "STCODE="+ textBox1.Text +" AND " + 
                    "STSEQ="+ dataGridView1\["STSEQ",dataGridView1.CurrentCell.RowIndex\].Value.ToString() +"  ";
                cmd.CommandText = strQuery;
                dr = cmd.ExecuteReader();
                if (dr.HasRows == false)
                {
                    dr.Close();
                    cmd.CommandText = "INSERT INTO PICTURES (STCODE,STRNO,STSEQ,FILENAME,FILESIZE,FILETYPE) " +
                        "VALUES(" + textBox1.Text + ", " +
                        "" + dataGridView1\["STRNO", dataGridView1.CurrentCell.RowIndex\].Value.ToString() + ", " +
                        "" + dataGridView1\["STSEQ", dataGridView1.CurrentCell.RowIndex\].Value.ToString() + ", " +
                        "'" + fileName + "'," + data.Length + ",'" + type + "') ";
                    //cmd.CommandText = "INSERT INTO PICTURES (STCODE,STRNO,STSEQ,FILENAME,FILETYPE) " +
                    //    "VALUES(" + textBox1.Text + ", " +
                    //    "" + dataGridView1\["STRNO", dataGridView1.CurrentCell.RowIndex\].Value.ToString() + ", " +
                    //    "" + dataGridView1\["STSEQ", dataGridView1.CurrentCell.RowIndex\].Value.ToString() + ",'" + textBox1.Text.Trim() + "\_" + textBox2.Text.Trim() + "." + type + "') ";
                    //    //"'" + fileName + "'," + data.Length + ",'" + type + "') ";
    
                    cmd.ExecuteNonQuery();
    

    (Riaz)

    T 1 Reply Last reply
    0
    • M M Riaz Bashir

      hi all I have uploaded a picture into table but i am stuck, that how may I show the picture in Crystal Reports from table. I used following codes to upload the picture it works fine

                  // load the file that we want to upload into memory
                  fileStream = new System.IO.FileStream(strFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                  reader = new System.IO.BinaryReader(fileStream);
                  data = reader.ReadBytes((int)fileStream.Length);
      
                  // open the connection to the database
                  //conn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AccessFile.Text);
                  //conn.Open();
      
                  // determine if the file already exists.  If the file does not already
                  // exist, add the file to the table.
                  cmd = new OleDbCommand();
                  cmd.Connection = Module.objConnection;
                  string strQuery = 
                      "SELECT \* FROM PICTURES WHERE " + 
                      "STCODE="+ textBox1.Text +" AND " + 
                      "STSEQ="+ dataGridView1\["STSEQ",dataGridView1.CurrentCell.RowIndex\].Value.ToString() +"  ";
                  cmd.CommandText = strQuery;
                  dr = cmd.ExecuteReader();
                  if (dr.HasRows == false)
                  {
                      dr.Close();
                      cmd.CommandText = "INSERT INTO PICTURES (STCODE,STRNO,STSEQ,FILENAME,FILESIZE,FILETYPE) " +
                          "VALUES(" + textBox1.Text + ", " +
                          "" + dataGridView1\["STRNO", dataGridView1.CurrentCell.RowIndex\].Value.ToString() + ", " +
                          "" + dataGridView1\["STSEQ", dataGridView1.CurrentCell.RowIndex\].Value.ToString() + ", " +
                          "'" + fileName + "'," + data.Length + ",'" + type + "') ";
                      //cmd.CommandText = "INSERT INTO PICTURES (STCODE,STRNO,STSEQ,FILENAME,FILETYPE) " +
                      //    "VALUES(" + textBox1.Text + ", " +
                      //    "" + dataGridView1\["STRNO", dataGridView1.CurrentCell.RowIndex\].Value.ToString() + ", " +
                      //    "" + dataGridView1\["STSEQ", dataGridView1.CurrentCell.RowIndex\].Value.ToString() + ",'" + textBox1.Text.Trim() + "\_" + textBox2.Text.Trim() + "." + type + "') ";
                      //    //"'" + fileName + "'," + data.Length + ",'" + type + "') ";
      
                      cmd.ExecuteNonQuery();
      

      (Riaz)

      T Offline
      T Offline
      thatraja
      wrote on last edited by
      #2

      Already answered similar question in Q/A section here before, see that. Crystal Report - Images[^] Printing photo on crystal report[^] Dynamically setting picture path in crystal report[^] Crystal Report Reading Picture file from path c: directory[^]

      thatraja


      **My Tip/Tricks
      My Dad had a Heart Attack on this day so don't...
      **All these are my opinions. Different people. different way of thinking. I am no one to judge others - Chandru

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups