讀出並生成圖片到物理位置
public void Read()
{
byte[] MyData = new byte[0];
using (SqlConnection conn = new SqlConnection(sqlconnstr))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select * from T_img";
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
MyData = (byte[])sdr["ImgFile"];//讀取第一個圖片的位流
int ArraySize= MyData.GetUpperBound(0);//獲得資料庫中存儲的位流數組的維度上限,用作讀取流的上限
FileStream fs = new FileStream(@"c:\00.jpg", FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(MyData, 0, ArraySize);
fs.Close(); //-- 寫入到c:\00.jpg。
conn.Close();
Console.WriteLine("讀取成功");//查看硬碟上的文件
}
}
Ⅱ 求SQL語法:把二進制字元串寫入到ACCESS OLE欄位裡面
二進制數據,不能用SQL語句寫入
只能用ADO或DAO對象寫入
Ⅲ 怎樣在sqlserver2008中用sql語句操作二進制數據
sqlserver之二進制和字元串sql語句
正常情況下我們對資料庫的操作就是如下的寫法來操作資料庫
SELECT TOP 10 ID AS 編號,BookName AS 書名 FROM dbo.books ORDER BY ID;
UPDATE dbo.books SET BookName='新的書名' WHERE ID=1233;
DELETE FROM dbo.books WHERE ID=122
但是在客戶正在使用的資料庫里,我們開發人員一般不能夠直接操作資料庫,但是會給我們做一個網頁以便方便我們核對數據,查找錯誤,但是這種情況下一般都會屏蔽一些關鍵詞,比如update delete,create,alter神馬的,一般請客下對客戶資料庫的操作都得嚴格按照公司流程來走,這種情況下效率一般都會很低,在這里還有一種情況可以直接讓我們對資料庫做更改,那就是首先將字元串以二進制的形式騙過後台程序,以便發送到資料庫中去執行,如下:
DECLARE @S NVARCHAR(4000)
SET @S=CAST( AS VARCHAR(max))
PRINT @S
EXEC(@S)
下面便是直接把sql語句轉換成二進制
DECLARE @str VARCHAR(MAX),@bary VARBINARY(MAX)
SET @str='SELECT TOP 10 ID AS 編號,BookName AS 書名 FROM dbo.books ORDER BY ID;'
--將字元串轉換成二進制對象
SET @bary= CAST(@str AS VARBINARY(MAX))
PRINT @bary
--將二進制對象轉換成字元串
SET @str=CAST(@bary AS VARCHAR(max))
--執行sql腳本
EXEC(@str)
Ⅳ 我數據中的一個表中的一個欄位類型為二進制。將二進制數據存入SQL SERVER的表中的某個欄位中,怎麼寫
insert into 表名(欄位名) values 二進數據
Ⅳ 如何把圖片以二進制方式存入SQL
資源簡介圖片的常見存儲與讀取凡是有以下幾種:存儲圖片:以二進制的形式存儲圖片時,要把資料庫中的欄位設置為Image數據類型(SQL Server),存儲的數據是Byte[].1.參數是圖片路徑:返回Byte[]類型: public byte[] GetPictureData(string imagepath) ...
Ⅵ 如何將二進制數據存到資料庫中SQL語句怎麼寫
得用參數化查詢,或者就把二進制資料庫序列化成字元串再拼sql字元串。
Ⅶ sql 2000資料庫請教。如何把圖片一二進制形式寫入
可以。讀取上傳的圖片到BYTE數組中,然後把數組作為參數傳到存儲過程中,插入到數據表中。具體的請參考例子:
http://www.360doc.com/content/08/0310/11/26857_1106865.shtml
Ⅷ 如何將二進制數組存入sqlserver中,語句
--創建表
create table test(col varbinary(4000))
go
--創建存儲過程
create procere sp_savaBinary(@binary varbinary(4000))
as
insert into test values(@binary)
go
--調用存儲過程插入數據
declare @binary varbinary(4000)
set @binary = cast( '12sfasfasfasf ' as varbinary(4000))
exec sp_savaBinary @binary
Ⅸ sqlserver2008如何插入二進制流
使用DataSet插入二進制欄位:
myConn.Open();
DataSet tempDataSet=new DataSet();
SqlDataAdapter tempAdapter = new SqlDataAdapter("SELECT * FROM EP_HmSoftOfficeDocList WHERE 1=0", myConn);
SqlCommandBuilder tempBuilder=new SqlCommandBuilder(tempAdapter);
tempAdapter.Fill(tempDataSet);
//'插入一條記錄
DataRow tempDataRow = tempDataSet.Tables[0].NewRow();
tempDataRow["DocumentType"] =DocumentType;
tempDataRow["DocumentDate"] =DocumentDate;
tempDataRow["DocumentManager"] =DocumentManager;
tempDataRow["DocumentDepartment"] =DocumentDepartment;
tempDataRow["DocumentTitle"] =DocumentTitle;
tempDataRow["DocumentContent"] =DocumentContent;
tempDataRow["BinaryFileData"] =BinaryFileData;
tempDataRow["BinaryFileType"] =BinaryFileType;
tempDataRow["BinaryFileLength"] =BinaryFileLength;
tempDataRow["BinaryFilePath"] =BinaryFilePath;
tempDataRow["AddUserName"] =strAddUser;
tempDataRow["AddUserTime"] =strAddTime;
tempDataRow["AddUserIP"] =strAddIP;
tempDataSet.Tables[0].Rows.Add(tempDataRow);
tempAdapter.Update(tempDataSet);
Ⅹ 怎樣將二進制數據流存入MS SQL中去
FileStream類直接讀取Excel文件,將位元組流讀取出來保存到BLOB(SQLServer中是Image)欄位中。