vb.net 保存图片到数据库 就差最后一步了,各位看看谢谢

蛋蛋の忧伤 2008-04-23 10:54:59
'变压器图片
Dim b() As Byte
Dim fs As IO.FileStream
Dim br As IO.BinaryReader
Public Function add_byqImages() As Boolean
dbobj.ConnectionStr = connDBStr
dbobj.ConnectDB()

Dim strsql As String = ""
'文件读入内存
Try
fs = New IO.FileStream("E:\1.jpg", IO.FileMode.Open, IO.FileAccess.Read)
br = New IO.BinaryReader(fs)
b = br.ReadBytes(fs.Length)
Catch ex As Exception
MsgBox("文件读入内存错误!" & ex.Message)
Finally
br.Close()
fs.Close()
End Try
'---------------------------------------
这里面的SQL语句的参数怎么写呢?谢谢

Try 图片编号 变压器编号 变压器图片(blob类型)
strsql = "insert into dygl_byq_img_info(img_id,byq_id,img) values({0},{1},?)"
strsql = String.Format(strsql, 1, 1)


'---------------------------------------
dbobj.DoWithBLOBField(strsql, "dd", b)
Catch ex As Exception
MsgBox("内存到数据库==" & ex.Message)
End Try

End Function
...全文
166 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
水如烟 2008-04-23
  • 打赏
  • 举报
回复
仅供参考:

http://topic.csdn.net/u/20080407/23/d1eebd54-257f-4888-b4a4-86aa54427beb.html
Plougher 2008-04-23
  • 打赏
  • 举报
回复
blob类型我没做过
你可以把blob类型字符串类型,然后把b()通过ConvertByteToString转换成字符串在Insert into 进去
蛋蛋の忧伤 2008-04-23
  • 打赏
  • 举报
回复
大家积极一些吧,5555555555
henrysap 2008-04-23
  • 打赏
  • 举报
回复
Dim FilStr As Stream
FilStr = File.Open("D:\Test.JPG", FileMode.Open, FileAccess.Read, FileShare.Read)
Dim a() As Byte
Dim b()
ReDim a(FilStr.Length)
FilStr.Read(a, 0, CInt(FilStr.Length))
Dim CON As New SqlConnection

Dim SqlStra As String = "dbo.Insert_Picture"
FilStr.Close()
CON.ConnectionString = "SERVER=;UID=;PWD=;DATABASE="
CON.Open()
Dim row As DataRow
row = Me.Dataset11.TB_PICTURE.NewRow
row(0) = "1"
row(1) = a
Me.Dataset11.TB_PICTURE.Rows.Add(row)
Dim myCommand As New SqlClient.SqlCommand(SqlStra, CON)
With myCommand.Parameters
.Add(New SqlParameter("@ID", SqlDbType.NVarChar, 50))
.Item("@ID").Value = "Test"

.Add(New SqlParameter("@PICTURE", SqlDbType.Image))
.Item("@PICTURE").Value = row(1)
End With
myCommand.CommandType = CommandType.StoredProcedure


myCommand.ExecuteNonQuery()
CON.Close()
蛋蛋の忧伤 2008-04-23
  • 打赏
  • 举报
回复
我真是火了!还有没有正事的!!!!
sugar8049 2008-04-23
  • 打赏
  • 举报
回复
我的例子 供你参考
Dim Buffer() As Byte
Dim Fs As New IO.FileStream(GridTz(i, 1), IO.FileMode.Open, IO.FileAccess.Read)
ReDim Buffer(Fs.Length)
Fs.Read(Buffer, 0, Fs.Length)
Length = Fs.Length
Fs.Close()
SqlCmd.CommandText = "update 房产_楼盘展示图 set 图片内容=@图片内容 where 楼盘ID=" & LpID & " and 图纸ID=" & TempPicId & ""
SqlCmd.Parameters.AddWithValue("@图片内容", Buffer)
SqlCmd.ExecuteNonQuery()
蛋蛋の忧伤 2008-04-23
  • 打赏
  • 举报
回复
大家怎么了

16,717

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧