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

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

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

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

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

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

VB+SQL图片存取vb代码 VB窗体界面如下: 1.把图片写入到Field中函数代码: PrivateSubpicsavetodb(ByReffldAsADODB.Field,diskfileAsString) Constblocksize=4096 Dimbytedata()AsByte DimnumblocksAsLong DimfilelengthAsLong DimleftoverAsLong DimsourcefileAsLong DimiAsLong sourcefile=FreeFile OpenTrim(CommonDialog1.filename)ForBinaryAccessReadAssourcefile filelength=LOF(sourcefile) Iffilelength=0Then Closesourcefile MsgBoxTrim(CommonDialog1.filename)&"无内容或不存在!" Else numblocks=filelength\blocksize leftover=filelengthModblocksize fld.Value=Null ReDimbytedata(blocksize) Fori=1Tonumblocks Getsourcefile,,bytedata() fld.AppendChunkbytedata() Next ReDimbytedata(leftover) Getsourcefile,,bytedata() fld.AppendChunkbytedata() Closesourcefile EndIf EndSub 2.把图片存入SQL数据库XS(学生表)中: PrivateSubCommand1_Click() DimsAsString Dimbytedata()AsByte DimadofldAsADODB.Field s="select*fromxswhere学号='"&Trim(Text1.Text)&"'" sqlres.Opens,connectstring,adOpenDynamic,adLockPessimistic IfNotsqlres.EOFThen Setadofld=sqlres.Fields("照片") IfCommonDialog1.filename<>""Then Callpicsavetodb(adofld,"filename") EndIf sqlres.Update 3.把图片从SQL数据库读入VB图片框: PrivateSubCommand3_Click() DimsqlresAsADODB.Recordset Setsqlres=NewADODB.Recordset sqlres.Open"select*fromxswhere学号='"&Trim(Text1.Text)&"'",connectstring,adOpenDynamic,adLockPessimistic DimstreamAsADODB.stream Setstream=NewADODB.stream stream.Mode=adModeReadWrite 'Image1.Picture=LoadPicture("") IfNotIsNull(sqlres.Fields("照片"))Then stream.Type=adTypeBinary stream.Open stream.Writesqlres.Fields("照片") stream.SaveToFile"filename",adSaveCreateOverWrite Image1.Picture=LoadPicture("filename") sqlres.Close stream.Close EndIf EndSub 4修改图片: PrivateSubCommand2_Click() DimfilenameAsString CommonDialog1.Filter="图像(*.jpg)|*.jpg|位图(*.bmp)|*.bmp" CommonDialog1.InitDir=App.Path&"\图片库" CommonDialog1.ShowOpen filename=CommonDialog1.filename Image1.Picture=LoadPicture(filename) EndSub