我有一个叫表IMG
,有列ID
,里面有Content
图片。
怎么可能从那里得到图片?
我用谷歌搜索了这个问题,我得到的只是 vb.net、c# 和 php - mysql。
也许有人可以说获取图片的最佳和最简单的方法是什么(示例、复制/粘贴代码、程序)?
谢谢!
我有一个叫表IMG
,有列ID
,里面有Content
图片。
怎么可能从那里得到图片?
我用谷歌搜索了这个问题,我得到的只是 vb.net、c# 和 php - mysql。
也许有人可以说获取图片的最佳和最简单的方法是什么(示例、复制/粘贴代码、程序)?
谢谢!
经过大量阅读和工作找到了解决方案!
这里是!工作 100%
Dim conn, sql, a, filename
Dim dir
dir = "c:\images\" //saves files into this directory
Dim fileObj
Set fileObj = CreateObject("Scripting.FileSystemObject")
Set conn = CreateObject("ADODB.Connection")
Dim strStream
Set strStream = CreateObject("ADODB.Stream")
Dim rstRecordset
Set rstRecordset = CreateObject("ADODB.Recordset")
conn.Open "Provider=SQLOLEDB;Data Source=yourserver;Integrated Security = SSPI","username","password"
rstRecordset.Open "Select xxx, yyy, zzz from table (nolock) where xxx = '' order by xxx desc", conn ', adOpenKeyset, adLockOptimistic
Set fso = CreateObject("Scripting.FileSystemObject")
While Not rstRecordset.EOF
filename = rstRecordset.Fields(0)
er = 0
Do
er = er+1
Loop While (fso.FileExists(dir & filename & "_" & er & ".JPG"))
filename = dir & filename & "_" & er & ".JPG"
strStream.Type = 1
strStream.Open
strStream.Write rstRecordset.Fields(2).Value
strStream.SaveToFile filename
strStream.Close
rstRecordset.MoveNext
Wend
这里是!
尝试这样的事情(来自 d_r_w 的回答):
SqlDataAdapter dataAdapter = new SqlDataAdapter(
new SqlCommand("SELECT pic FROM imageTest WHERE pic_id = 1",
yourConnectionReference));
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
if (dataSet.Tables[0].Rows.Count == 1)
{
Byte[] data = new Byte[0];
data = (Byte[])(dataSet.Tables[0].Rows[0]["pic"]);
MemoryStream mem = new MemoryStream(data);
yourPictureBox.Image= Image.FromStream(mem);
}
看看完整的答案
执行此操作的更多选项:
我发现这篇文章是关于 PHP 但使用 MySQL(你需要更改与服务器的连接):
<?php
// image.php - by Hermawan Haryanto <hermawan@dmonster.com>
// Example PHP Script, demonstrating Storing Image in Database
// Detailed Information can be found at http://www.codewalkers.com
// database connection
$conn = mysql_connect("localhost", "user", "password")
OR DIE (mysql_error());
@mysql_select_db ("hermawan", $conn) OR DIE (mysql_error());
$sql = "SELECT * FROM image WHERE image_id=".$_GET["iid"];
$result = mysql_query ($sql, $conn);
if (mysql_num_rows ($result)>0) {
$row = @mysql_fetch_array ($result);
$image_type = $row["image_type"];
$image = $row["image"];
Header ("Content-type: $image_type");
print $image;
}
?>