问题描述
数据库中存的是图片的地址,如D:projectsrcimagesB_03.jpg如何根据数据库显示图片?各位帮帮忙啊~~~~~~~~
解决方案
解决方案二:
在网上找的,希望是lz需要的。references:http://inspirone.blogspot.com/2007/01/loading-images-dynamically-in-crystal.htmlhttp://www.neodynamic.com/ND/FaqsTipsTricks.aspx?tabid=66&prodid=1&sid=69---------ThesolutionistodynamicallyaddanbinarycolumntotheXSDdatasetandinthedatasetcontainingthedatatobeprinted.Thenloadtheimagefileasbinarydataintothedataset.1.Inacolumninyourdatabasetablestorethepathtotheimagethatneedstobedisplayedinacrystalreportdocument,inthisexampletheimagepathcolumnnameis"ImagePath".2.CreateanewDataset/XMLschema(xsd)inVS.Netthatmapsthefieldsinthedatabasetable.Thisshouldbethenormalprocedurewhencreatingareport.InthisXSDDataSetaddanadditionalfieldthatisnotinthetableandwhichisoftypebase64Binary:xs:elementname="Image"type="xs:base64Binary"minOccurs="0"Notethattheopeningandclosingtagsaremissingabovesinceitwon'tbeprintedonthissite.Justaddenclosetheabovein"</>"3.WhendesigningthereportbasedonthisDataSet,draganddropthe"Image"fieldintheregionwhereyouwantittoappear.4.Addthefollowingprocedurestoyourcode:PrivateSubAddImageColumn(ByValobjDataTableAsDataTable,ByValstrFieldNameAsString)Try'createthecolumntoholdthebinaryimageDimobjDataColumnAsDataColumn=NewDataColumn(strFieldName,Type.GetType("System.Byte[]"))objDataTable.Columns.Add(objDataColumn)CatchexAsExceptionThrowNewException(ex.Message)EndTryEndSub'*...andthisonetoloadtheimageintheaboveaddedfield:PrivateSubLoadImage(ByValobjDataRowAsDataRow,ByValstrImageFieldAsString,ByValFilePathAsString)TryDimfsAsSystem.IO.FileStream=NewSystem.IO.FileStream(FilePath,System.IO.FileMode.Open,System.IO.FileAccess.Read)DimImage()AsByte=NewByte(fs.Length){}fs.Read(Image,0,CType(fs.Length,Integer))fs.Close()objDataRow(strImageField)=ImageCatchexAsExceptionThrowNewException(ex.Message)EndTryEndSub5.Beforeassigningthedatasettothe"SetDataSource"ofyourreport,addthefollowingcode:'Fillthedataset"DS"asrequiredwithdatatobedisplayedonthereport'*BegincodetoaddAddImageColumn(DS.Tables(0),"Image")'LooptoloadtheimageforeachrowForindexAsInteger=0ToDS.Tables(0).Rows.Count-1IfNotString.IsNullOrEmpty(DS.Tables(0).Rows(index).Item("ImagePath").ToString)ThenLoadImage(DS.Tables(0).Rows(index),"Image",_DS.Tables(0).Rows(index).Item("ImagePath").ToString)Else'*Youcouldloadadefaultimagehere,like"noimagetodisplay"'*ifyouhaveastandardonethenun-commentthecodebelowandchangetheimagepath'LoadImage(DS.Tables(0).Rows(index),"Image","c:MyDefaultImage.JPG")EndIfNext'*EndcodetoaddrptDoc.SetDataSource(DS.Tables(0))'Displayreportinareportviewercontrol