读出并生成图片到物理位置
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)字段中。