预览加载中,请您耐心等待几秒...
1/7
2/7
3/7
4/7
5/7
6/7
7/7

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

VB+SQL图片存取vb代码VB窗体界面如下:1.把图片写入到Field中函数代码:PrivateSubpicsavetodb(ByReffldAsADODB.Field,diskfileAsString)Constblocksize=4096Dimbytedata()AsByteDimnumblocksAsLongDimfilelengthAsLongDimleftoverAsLongDimsourcefileAsLongDimiAsLongsourcefile=FreeFileOpenTrim(CommonDialog1.filename)ForBinaryAccessReadAssourcefilefilelength=LOF(sourcefile)Iffilelength=0ThenClosesourcefileMsgBoxTrim(CommonDialog1.filename)&"无内容或不存在!"Elsenumblocks=filelength\blocksizeleftover=filelengthModblocksizefld.Value=NullReDimbytedata(blocksize)Fori=1TonumblocksGetsourcefile,,bytedata()fld.AppendChunkbytedata()NextReDimbytedata(leftover)Getsourcefile,,bytedata()fld.AppendChunkbytedata()ClosesourcefileEndIfEndSub2.把图片存入SQL数据库XS(学生表)中:PrivateSubCommand1_Click()DimsAsStringDimbytedata()AsByteDimadofldAsADODB.Fields="select*fromxswhere学号='"&Trim(Text1.Text)&"'"sqlres.Opens,connectstring,adOpenDynamic,adLockPessimisticIfNotsqlres.EOFThenSetadofld=sqlres.Fields("照片")IfCommonDialog1.filename<>""ThenCallpicsavetodb(adofld,"filename")EndIfsqlres.Update3.把图片从SQL数据库读入VB图片框:PrivateSubCommand3_Click()DimsqlresAsADODB.RecordsetSetsqlres=NewADODB.Recordsetsqlres.Open"select*fromxswhere学号='"&Trim(Text1.Text)&"'",connectstring,adOpenDynamic,adLockPessimisticDimstreamAsADODB.streamSetstream=NewADODB.streamstream.Mode=adModeReadWrite'Image1.Picture=LoadPicture("")IfNotIsNull(sqlres.Fields("照片"))Thenstream.Type=adTypeBinarystream.Openstream.Writesqlres.Fields("照片")stream.SaveToFile"filename",adSaveCreateOverWriteImage1.Picture=LoadPicture("filename")sqlres.Closestream.CloseEndIfEndSub4修改图片:PrivateSubCommand2_Click()DimfilenameAsStringCommonDialog1.Filter="图像(*.jpg)|*.jpg|位图(*.bmp)|*.bmp"CommonDialog1.InitDir=App.Path&"\图片库"CommonDialog1.ShowOpenfilename=CommonDialog1.filenameImage1.Picture=LoadPicture(filename)EndSub举个例子吧,建一个数据库F:/1.mdb,表“员工”,字段“工号”,“照片”(类型:备注)PrivateSubPicture1_Click()DimconAsNewADODB.ConnectionDimadorsAsNewADODB.RecordsetDimiStmAsNewADODB.StreamCommonDialog1.Filter="ALLFIELS(*.jpg)|*.jpg"CommonDialog1.Ac