图片批量上传

tangserver 2008-11-18 04:27:31
现在我有一个文件夹里面都是图片,我要把这些图片全部上传到数据库中,数据库表A有3个字段
ID 为自动增长列 图片名称为nvarchar(50) 图片为varbinary(MAX)
请问改怎么实现呢,能否给个代码看看
...全文
110 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tangserver 2008-11-19
  • 打赏
  • 举报
回复
好像只能用循环做了
wuyq11 2008-11-19
  • 打赏
  • 举报
回复
参考:
http://www.cnblogs.com/tzwhx/archive/2008/10/04/1303801.html
先取得路径,再循环把图片文件插入数据库
shily_fly 2008-11-19
  • 打赏
  • 举报
回复
应该是WEB的吧
前段时间也有这个,网上很多的,可以去找一下
acqy 2008-11-18
  • 打赏
  • 举报
回复

Dim con As New SqlConnection("Server=yileiw2;uid=sqlauth;pwd=sqlauth;database=pubs")
Dim da As New SqlDataAdapter("Select * From pub_info", con)
Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
Dim ds As New DataSet()

da.MissingSchemaAction = MissingSchemaAction.AddWithKey
con.Open()
da.Fill(ds, "Pub_info")

Dim fs As New FileStream _
("C:\SomePath\MyPhoto.jpg", FileMode.OpenOrCreate, _
FileAccess.Read)
Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
ds.Tables("Pub_info").Rows(0)("logo") = MyData
da.Update(ds, "Pub_info")

fs = Nothing
MyCB = Nothing
ds = Nothing
da = Nothing

con.Close()
con = Nothing
Response.Write("File saved to database")
chenaini1314 2008-11-18
  • 打赏
  • 举报
回复
把图片转换为二进制文件后保存就可以了呀
qinhl99 2008-11-18
  • 打赏
  • 举报
回复
是web 还是winform?

111,131

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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