| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1708 人关注过本帖
标题:[求助]怎么实现上传相片?并存到数据库中
只看楼主 加入收藏
chen5322
Rank: 1
等 级:新手上路
帖 子:63
专家分:0
注 册:2006-5-25
收藏
得分:0 
可以了吗 不行的话给我留言 我再发个完整的给你 QQ:262050611
2006-12-07 13:21
ncqingchuan
Rank: 1
等 级:新手上路
帖 子:58
专家分:0
注 册:2006-8-8
收藏
得分:0 
Dim Myset As DataSet
Dim Myadp As OleDbDataAdapter
Dim Opendia As New OpenFileDialog
Opendia.Filter = "Image File(*.JPG;*.BMP;*.JPEG)|*.JPG;*.BMP;*.JPEG"
Dim result As DialogResult = Opendia.ShowDialog
If result = DialogResult.Cancel Then
Exit Sub
End If
Dim Filename As String = Opendia.FileName
Dim Mycon As New OleDbConnection
Mycon.ConnectionString = "provider=Microsoft.JET.OLEDB.4.0;data source=" & Application.StartupPath & "\image.mdb"
Mycon.Open()
Myadp = New OleDbDataAdapter("select * from photo", Mycon)
Myset = New DataSet
Myadp.Fill(Myset, "Pho")
Dim FS As FileStream
FS = New FileStream(Filename, FileMode.Open)
Dim Filestream As New BinaryReader(FS)
Dim Myimg As Byte()
Myimg = Filestream.ReadBytes(FS.Length)
picbox.Image = Image.FromStream(FS)
Try
Dim Mycmd As New OleDbCommand
Mycmd.Connection = Mycon
Mycmd.CommandText = "insert into photo([image]) values (@image)"
Mycmd.CommandType = CommandType.Text
Dim MyP As OleDbParameter = Mycmd.Parameters.Add("@image", OleDbType.LongVarBinary)
MyP.Value = Myimg
Mycmd.ExecuteNonQuery()
Catch ex As SqlException
MsgBox(ex.Message)
End Try
Filestream.Close()
FS.Close()
Mycon.Close()
End Sub
Dim Myset1 As New DataSet
Dim FS As New FileStream("Qing", FileMode.Create)
Dim Stream1 As New BinaryWriter(FS)
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
Dim Mycon As New OleDbConnection("provider=Microsoft.JET.OLEDB.4.0;data source=" & Application.StartupPath & "\image.mdb")
Mycon.Open()
Dim myadp As New OleDbDataAdapter("Select * from Photo", Mycon)
myadp.Fill(Myset1, "Pho")
Stream1.Write(Myset1.Tables("Pho").Rows(0).Item("Image"))
picbox.Image = Image.FromStream(FS)
Stream1.Close()
FS.Close()
Mycon.Close()
Kill("qing")
2006-12-21 08:05
ninggang
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:637
专家分:0
注 册:2006-11-1
收藏
得分:0 
讲得非常详细,呵呵,顶一下,总结一下,首先数据库的连接这块知识要懂.第二,需要用到文件流的知识如:FileStream,I/O相关的一些知识,在扩展一下,就涉及到很多的如:MemoryStream,BufferedSream,NetWorkStream(用于Socket的数据读写)

大家一起努力,共同打造未来!!
2006-12-29 10:27
scindy
Rank: 1
等 级:新手上路
威 望:1
帖 子:591
专家分:4
注 册:2006-10-23
收藏
得分:0 
你在数据库中保存照片的路径就可以了~~~,等用的时候调用就可以了~~~



淘宝新到货: http://shop36082390. 电脑及配件/杀毒U盘/移动硬盘/减肥产品/切苹果器/剥蒜器/个性烟灰缸/装饰彩灯/雨伞/女包//手机座/极品铁观间茶叶/五层布衣柜/三洋/日立投影机
QQ:410243392 (常用)
2007-03-22 17:11
快速回复:[求助]怎么实现上传相片?并存到数据库中
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015850 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved