首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Access >

急求关于数据库中图片的插入的有关问题!

2012-02-20 
急求关于数据库中图片的插入的问题!!!!!我们的主页上的所陈列的商品图片都是从我们数据库里面读取的,写入

急求关于数据库中图片的插入的问题!!!!!
我们的主页上的所陈列的商品图片都是从我们数据库里面读取的,写入数据库的这些图片的数据时改图片的路径,现在我们的问题是,我们在后台的商品添加页面,我们要向商品表里面添加商品的缩略图和大图,在添加的时候呢,我们是用文件域来获取该图片的地址好一些,还是用上传图片好一些呢?在这方面我还是有些不太懂其原理,请大虾们指点迷津,赐予我好的方法和建议,感激不尽!!如果能在这些方面帮我做做系统的解释那就更好!!!谢谢!!

[解决办法]
利用ADO的二进制流把文件以二进制数据写入到ole字段。

AppendChunk 和 GetChunk 方法范例 (VB)
本范例使用 AppendChunk 和 GetChunk 方法用其他记录中的数据填充图像字段。

VB code
'BeginAppendChunkVB    'To integrate this code    'replace the data source and initial catalog values    'in the connection string    Public Sub Main()    On Error GoTo ErrorHandler    'recordset and connection variables    Dim Cnxn As ADODB.Connection    Dim strCnxn As String    Dim rstPubInfo As ADODB.Recordset    Dim strSQLPubInfo As String     'record variables    Dim strPubID As String    Dim strPRInfo As String    Dim lngOffset As Long    Dim lngLogoSize As Long    Dim varLogo As Variant    Dim varChunk As Variant    Dim strMsg As String        Const conChunkSize = 100        ' Open a connection    Set Cnxn = New ADODB.Connection    strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _        "Initial Catalog='Pubs';Integrated Security='SSPI';"    Cnxn.Open strCnxn        ' Open the pub_info table with a cursor that allows updates    Set rstPubInfo = New ADODB.Recordset    strSQLPubInfo = "pub_info"    rstPubInfo.Open strSQLPubInfo, Cnxn, adOpenKeyset, adLockOptimistic, adCmdTable        ' Prompt for a logo to copy    strMsg = "Available logos are : " & vbCr & vbCr    Do While Not rstPubInfo.EOF        strMsg = strMsg & rstPubInfo!pub_id & vbCr & _            Left(rstPubInfo!pr_info, InStr(rstPubInfo!pr_info, ",") - 1) & _            vbCr & vbCr        rstPubInfo.MoveNext    Loop       strMsg = strMsg & "Enter the ID of a logo to copy:"    strPubID = InputBox(strMsg)        ' Copy the logo to a variable in chunks    rstPubInfo.Filter = "pub_id = '" & strPubID & "'"    lngLogoSize = rstPubInfo!logo.ActualSize    Do While lngOffset < lngLogoSize        varChunk = rstPubInfo!logo.GetChunk(conChunkSize)        varLogo = varLogo & varChunk        lngOffset = lngOffset + conChunkSize    Loop       ' Get data from the user    strPubID = Trim(InputBox("Enter a new pub ID" & _                             " [must be > 9899 & < 9999]:"))                                 strPRInfo = Trim(InputBox("Enter descriptive text:"))        ' Add the new publisher to the publishers table to avoid    ' getting an error due to foreign key constraint    Cnxn.Execute "INSERT publishers(pub_id, pub_name) VALUES('" & _                   strPubID & "','Your Test Publisher')"        ' Add a new record, copying the logo in chunks    rstPubInfo.AddNew    rstPubInfo!pub_id = strPubID    rstPubInfo!pr_info = strPRInfo    lngOffset = 0 ' Reset offset    Do While lngOffset < lngLogoSize        varChunk = LeftB(RightB(varLogo, lngLogoSize - lngOffset), _            conChunkSize)        rstPubInfo!logo.AppendChunk varChunk        lngOffset = lngOffset + conChunkSize    Loop    rstPubInfo.Update       ' Show the newly added data    MsgBox "New record: " & rstPubInfo!pub_id & vbCr & _        "Description: " & rstPubInfo!pr_info & vbCr & _        "Logo size: " & rstPubInfo!logo.ActualSize    ' Delete new records because this is a demo    rstPubInfo.Requery    Cnxn.Execute "DELETE FROM pub_info " & _        "WHERE pub_id = '" & strPubID & "'"    Cnxn.Execute "DELETE FROM publishers " & _        "WHERE pub_id = '" & strPubID & "'"    ' clean up    rstPubInfo.Close    Cnxn.Close    Set rstPubInfo = Nothing    Set Cnxn = Nothing    Exit Sub    ErrorHandler:   ' clean up    If Not rstPubInfo Is Nothing Then        If rstPubInfo.State = adStateOpen Then rstPubInfo.Close    End If    Set rstPubInfo = Nothing        If Not Cnxn Is Nothing Then        If Cnxn.State = adStateOpen Then Cnxn.Close    End If    Set Cnxn = Nothing        If Err <> 0 Then        MsgBox Err.Source & "-->" & Err.Description, , "Error"    End IfEnd Sub'EndAppendChunkVB 


[解决办法]
存储照片的路径信息可以吧?学习!
[解决办法]
不是吧,这么复杂啊?不是将图片上传到站点下的图片文件夹里面,再将路径写入数据库,再在页面上读取吗?---------------你的问题都是ASP问题, request对象如何取二进制流,如何用fso将二进制流保存为文件,路径保存在数据库中只是存文本而已。跟其他存文字完全一样,没有什么图片的特殊性。

因此建议你去ASP板块提问,而不是 ACCESS 板块
[解决办法]
现成例子:
http://download.csdn.net/source/1483930

热点排行