日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql varbinary blob_从数据库中读取SQL Varbinary Blob

發布時間:2023/12/10 数据库 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql varbinary blob_从数据库中读取SQL Varbinary Blob 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我正在努力將文件保存到sql blob到varbinary(max)列,并且現在有了保存方面的工作(我相信).

我無法弄清楚如何讀取數據,因為我正在使用存儲過程檢索我的數據庫值我應該能夠訪問列數據,如ds.Tables [0] .Rows [0] [ "blobData"]; 所以我有必要像我在下面的例子中看到的那樣有一個SQLCommand等:

private void OpenFile(string selectedValue)

{

String connStr = "...connStr";

fileName = ddlFiles.GetItemText(ddlFiles.SelectedItem);

using (SqlConnection conn = new SqlConnection(connStr))

{

conn.Open();

using (SqlCommand cmd = conn.CreateCommand())

{

cmd.CommandText = "SELECT BLOBData FROM BLOBTest WHERE testid = " + selectedValue;

using (SqlDataReader dr = cmd.ExecuteReader())

{

while (dr.Read())

{

int size = 1024 * 1024;

byte[] buffer = new byte[size];

int readBytes = 0;

int index = 0;

using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))

{

while ((readBytes = (int)dr.GetBytes(0, index, buffer, 0, size)) > 0)

{

fs.Write(buffer, 0, readBytes);

index += readBytes;

}

}

}

}

}

}

當我可以在沒有sqlcommand的情況下訪問我需要的列時,有更簡單的方法嗎?

希望我在我的問題中足夠清楚,如果不是那么問我會詳細說明!

更新:

現在情況如此 - 我有我的存儲過程返回的blobData列的值,并且可以將其傳遞到內存流并調用'LoadDocument(memStream); 但是這會導致亂碼文本而不是我實際顯示的文件.

我現在的問題是有沒有辦法獲得完整的路徑,包括存儲在SQL Blob中的文件的文件擴展名?我目前正在考慮使用Filetable,希望我能夠獲得完整的路徑.

更新2:

我嘗試創建一個臨時文件并閱讀這個無濟于事(仍然是胡言亂語)

string fileName = System.IO.Path.GetTempFileName().ToString().Replace(".tmp", fileExt);

using (MemoryStream myMemoryStream = new MemoryStream(blobData, 0, (int)blobData.Length, false, true))

{

using (FileStream myFileStream1 = File.Create(fileName))

{

myMemoryStream.WriteTo(myFileStream1);

myMemoryStream.Flush();

myMemoryStream.Close();

myFileStream1.Flush();

myFileStream1.Close();

FileInfo fi = new FileInfo(fileName);

Process prc = new Process();

prc.StartInfo.FileName = fi.FullName;

prc.Start();

}

}

干杯,H

總結

以上是生活随笔為你收集整理的mysql varbinary blob_从数据库中读取SQL Varbinary Blob的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。