以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 图片文件插入数据库的问题,两种方案都不行?! (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=176371) |
-- 作者:kylin -- 发布时间:2022/4/10 21:59:00 -- 图片文件插入数据库的问题,两种方案都不行?! 1、方案1: Dim img As Image = GetImage("H:\\桌面\\网络PNG图标\\AMR000003.png") Dim cmd As new SQLCommand cmd.C cmd.CommandText = "Insert Into EvdDoc (DtNam, DocFld,FlTm,EvdDoc) Values(?,?,?,?)" cmd.Parameters.Add("@DtNam","CeShi1") cmd.Parameters.Add("@DocFld","Nun") cmd.Parameters.Add("@FlTm",Date.Now) cmd.Parameters.Add("@EvdDoc",img ) cmd.ExecuteNonQuery 2、方案2 Dim fs As New IO.FileStream("H:\\桌面\\网络PNG图标\\AMR000003.png", IO.FileMode.Open , IO.FileAccess.Read) \'用文件流打开图片 Dim br As New IO.BinaryReader(fs) \'根据文件流,申明一个二进制阅读器 Dim ImageByte() As Byte = br.ReadBytes(fs.Length) \'阅读器读取文件流,并将读到的二进制放入数组ImageByte中, Dim ImageString As String = BitConverter.ToString(imageByte).Replace("-", "") Dim cmd As new SQLCommand cmd.C cmd.CommandText = "Insert Into EvdDoc (DtNam, DocFld,FlTm,EvdDoc) Values(?,?,?,?)" cmd.Parameters.Add("@DtNam","CeShi1") cmd.Parameters.Add("@DocFld","Nun") cmd.Parameters.Add("@FlTm",Date.Now) cmd.Parameters.Add("@EvdDoc","Ox" + ImageString ) cmd.ExecuteNonQuery |
-- 作者:有点蓝 -- 发布时间:2022/4/10 22:25:00 -- http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=170178&replyID=145330&skin=1 |
-- 作者:kylin -- 发布时间:2022/4/10 23:39:00 -- 谢谢! |