Need to show image from image path stored in mysql to Crystal Report Viewer in C#(VS 2008) -


i need show image dynamically in crystal report mysql image path in c# (visual studio 2008). have stored image path in mysql db, couldnt able display image on cr. code have tested not working. lots of goggling done in this, cant find solutions still. please help..!!

datatable dt = new datatable();             string student = "select `photo_path` `tc` `register_no`= '" + reg_no + "';";           //  mysqlconnection con = new mysqlconnection(conn);             //con.open();             mysqlcommand cmd1 = new mysqlcommand(student, conn);             mysqldatareader detail1 = cmd1.executereader();             reportdocument rptdoc = new reportdocument();             mysqldataadapter da = new mysqldataadapter(); // .xsd file name             da.selectcommand = cmd1;             da.fill(dt);             while (detail1.read())             {                 string image = detail1.getstring(0);             }             detail1.close();             conn.close();  dt.columns.add("image", system.type.gettype("system.byte[]"));            filestream fs;            //if (file.exists(image))            //{            //    fs = new filestream(image, filemode.open);            //}            //else            //{            //    messagebox.show("please file not exist");            //}           binaryreader br = new binaryreader(fs);            byte[] imgbyte = new byte[fs.length + 1];            imgbyte = br.readbytes(convert.toint32((fs.length)));             foreach (datarow dr in dt.rows)            {                dr["image"] = imgbyte;            }            tc_report myreport = new tc_report();            myreport.setdatasource(dt);            crystalreportviewer1.reportsource = myreport;            crystalreportviewer1.refresh(); 

i adding full code form load of crystal report viewer. getting error "you can provide single value parameter" , asks discrete value, if give value doesn't show report . generates report data not image if command lines below /////////// have marked in code. having tough time crystal report showing image database. whats wrong code please help..

 //creating object of report document class     reportdocument reportdocument = new reportdocument();     //creating object of parameterfield class     parameterfield paramfield = new parameterfield();     //creating object of parameterfields class     parameterfields paramfields = new parameterfields();     //creating object of parameterdiscretevalue class     parameterdiscretevalue paramdiscretevalue = new parameterdiscretevalue();     paramfield.name = "studenttc";     //set parameter value     paramdiscretevalue.value = reg_no;     //add parameter value in parameterfield object     paramfield.currentvalues.add(paramdiscretevalue);     //add parameter in parameterfields object     paramfields.add(paramfield);     //set parameterfield information in crystal report     crystalreportviewer1.parameterfieldinfo = paramfields;     mysqlconnection conn;     mysqlcommand cmd;     mysqldataadapter adap;     // messagebox.show(reg_no);     // code data database      conn = new mysqlconnection("server=localhost; database=mcet; user id=root; password=; charset=utf8;");     conn.open();     cmd = conn.createcommand();     cmd.commandtext = "select t2.photo_path,title, firstname, father_name, mother_name, gender, date_format(dob, '%d-%m-%y') dob, dobw, nationality, e_mail, religion, caste, community, admission_no, degree, department,date_format(doa, '%d-%m-%y') doa, date_format(dol, '%d-%m-%y') dol, lentry student_details t1 left join tc t2 on t1.register_no = t2.register_no t1.register_no='" + reg_no + "' ";     adap = new mysqldataadapter();     adap.selectcommand = cmd;        tc_dataset studentdb = new tc_dataset();         //var studentdb = new dataset();         studentdb.clear();         adap.fill(studentdb, "student");          // create crystalreport1 object          tc_report myreport = new tc_report();         // set datasource of report          myreport.setdatasource(studentdb);         // set report source reportview          crystalreportviewer1.reportsource = myreport;        // crystalreportviewer1.refresh();         ///////////////////////////////////////////////////////////////////////////////////////////////          datatable dt = new datatable();         mysqldatareader detail1 = cmd.executereader();         reportdocument rptdoc = new reportdocument();         while (detail1.read())         {             string image = detail1.getstring(0);         }         detail1.close();         mysqldataadapter da = new mysqldataadapter(); //          da.selectcommand = cmd;         da.fill(dt);         conn.close();         dt.columns.add("image", system.type.gettype("system.byte[]"));         filestream fs;         fs = new filestream("e:\\student\\photo\\" + reg_no + ".jpg", filemode.open);         //string path = path.combine("e:\\student\\photo\\", reg_no) + ".jpg";          //if (file.exists(path))         //{         //    fs = new filestream("e:\\student\\photo\\" + reg_no + ".jpg", filemode.open);         //}         //else         //{          //    messagebox.show("please file not exist");          //}         binaryreader br = new binaryreader(fs);         byte[] imgbyte = new byte[fs.length + 1];         imgbyte = br.readbytes(convert.toint32((fs.length)));          foreach (datarow dr in dt.rows)         {             dr["image"] = imgbyte;         }         tc_report myreport1 = new tc_report();         myreport1.setdatasource(dt);         crystalreportviewer1.reportsource = myreport1;         crystalreportviewer1.refresh();  

@utility, helping me out work done. code storing image blob datatype in mysql , bring cr using parameter dynamically.

     mysqlconnection conn;      mysqlcommand cmd;      mysqldataadapter adap;      // code data database     conn = new mysqlconnection("server=localhost; database=dbname; user id=root; password=; charset=utf8;");     conn.open();     cmd = conn.createcommand();     cmd.commandtext = "select photo_path,title, firstname student_details `register_no`='" + reg_no + "' ";     adap = new mysqldataadapter();     adap.selectcommand = cmd;        tc_dataset studentdb = new tc_dataset();    //tc_dataset dataset name, have created.     studentdb.clear();     adap.fill(studentdb, "tc_dt");     // tc_dt datatable name in dataset      // create crystalreport1 object      tc_report myreport = new tc_report();    //tc_report name of crystal report (rpt file)     textobject txt1 = (textobject)myreport.reportdefinition.sections["section1"].reportobjects["text68"]; **//  used send data text box cr (text68) textfield name in cr, year_leaving contains date of textbox string.**     txt1.text = year_leaving;     textobject txt2 = (textobject)myreport.reportdefinition.sections["section1"].reportobjects["text21"];     txt2.text = reason_leaving;     // set datasource of report     myreport.setdatasource(studentdb);     // set report source reportview      crystalreportviewer1.reportsource = myreport;  //crystalreportviewer1 cr viewer name in form  

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -