请问,SQL2000图片如何存储及读取啊?
我前台用的是Visual Studio 2005.
我前台用的是Visual Studio 2005.
解决方案 »
- 求SQL Server 2000 SP4 64位组件(SQL2000-KB884525-SP4-ia64.EXE)
- SQL分组问题,谢谢
- 同一台server里面有两个数据库更新
- SQL 2005补丁包 SP1 出错 Integration Serivces 服务不能启动。
- 一个有关SQL语句的问题
- 求助高手!这个where isnull(spec,'q')='q'子句为什么能够做到的呢????
- SQL将一张表的部分数据查询后插入到另一张表并同时删除从原表查询的数据
- 关于查询统计的问题
- SQL语句判断空值相等
- 自定义函数调用问题:高手请进
- 解析一段代码与语法,不胜感激。
- mysql中关于创建数据库的sql语句,很菜,大家多帮帮忙!
VB6向SQL SERVER存入图象:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;258038
VB.NET向SQL SERVER存入图象:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;308042
C#向SQL SERVER存入图象:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;309158
("Server=YourServer;uid=<username>;pwd=<strong 解password>;database=northwind")
Dim da As New SqlDataAdapter _
("Select * From MyImages", con)
Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
Dim ds As New DataSet()
da.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim fs As New FileStream _
("C:\winnt\Gone Fishing.BMP", FileMode.OpenOrCreate, _
FileAccess.Read)
Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
con.Open()
da.Fill(ds, "MyImages")
Dim myRow As DataRow
myRow = ds.Tables("MyImages").NewRow()
myRow("Description") = "This would be description text"
myRow("imgField") = MyData
ds.Tables("MyImages").Rows.Add(myRow)
da.Update(ds, "MyImages")
fs = Nothing
MyCB = Nothing
ds = Nothing
da = Nothing
con.Close()
con = Nothing
MsgBox ("Image saved to database")
Double-click Button2, and then add the following code to the Button2_Click event handler:
Note You must change uid <username> and pwd =<strong password> to the correct values before you run this code. Make sure that User ID has the appropriate permissions to perform this operation on the database.
Dim con As New SqlConnection _
("Server=YourServer;uid=<username>;pwd=<strong password>;database=northwind")
Dim da As New SqlDataAdapter _
("Select * From MyImages", con)
Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
Dim ds As New DataSet()
con.Open()
da.Fill(ds, "MyImages")
Dim myRow As DataRow
myRow = ds.Tables("MyImages").Rows(0)
Dim MyData() As Byte
MyData = myRow("imgField")
Dim K As Long
K = UBound(MyData)
Dim fs As New FileStream _
("C:\winnt\Gone Fishing2.BMP", FileMode.OpenOrCreate, _
FileAccess.Write)
fs.Write(MyData, 0, K)
fs.Close()
fs = Nothing
MyCB = Nothing
ds = Nothing
da = Nothing
con.Close()
con = Nothing
MsgBox ("Image retrieved")
1、建立过程
CREATE PROCEDURE sp_textcopy (
@srvname varchar (30),
@login varchar (30),
@password varchar (30),
@dbname varchar (30),
@tbname varchar (30),
@colname varchar (30),
@filename varchar (30),
@whereclause varchar (40),
@direction char(1))
AS
DECLARE @exec_str varchar (255)
SELECT @exec_str =
'textcopy /S ' + @srvname +
' /U ' + @login +
' /P ' + @password +
' /D ' + @dbname +
' /T ' + @tbname +
' /C ' + @colname +
' /W "' + @whereclause +
'" /F ' + @filename +
' /' + @direction
EXEC master..xp_cmdshell @exec_str 2、建表和初始化数据
create table 表名 (编号 int,image列名 image)
go
insert 表名 values(1,0x) -- 必须的,且不是null
insert 表名 values(2,0x) -- 必须的,且不是null
go3、读入
sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\图片.bmp','where 编号=1','I' --注意条件是 编号=1sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\bb.doc','where 编号=2','I' --注意条件是 编号=2go4、读出成文件
sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\图片.bmp','where 编号=1','O' --注意条件是 编号=1sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\bb.doc','where 编号=2','O' --注意条件是 编号=2
go************如果报textcopy不是可执行文件的话,你就到
C:\Program Files\Microsoft SQL Server\MSSQL\Binn
目录下拷备 textcopy.exe到:
C:\Program Files\Microsoft SQL Server\80\Tools\Binn
用image类型方法:
1、建立过程
CREATE PROCEDURE sp_textcopy (
@srvname varchar (30),
@login varchar (30),
@password varchar (30),
@dbname varchar (30),
@tbname varchar (30),
@colname varchar (30),
@filename varchar (30),
@whereclause varchar (40),
@direction char(1))
AS
DECLARE @exec_str varchar (255)
SELECT @exec_str =
'textcopy /S ' + @srvname +
' /U ' + @login +
' /P ' + @password +
' /D ' + @dbname +
' /T ' + @tbname +
' /C ' + @colname +
' /W "' + @whereclause +
'" /F ' + @filename +
' /' + @direction
EXEC master..xp_cmdshell @exec_str 2、建表和初始化数据
create table 表名 (编号 int,image列名 image)
go
insert 表名 values(1,0x) -- 必须的,且不是null
insert 表名 values(2,0x) -- 必须的,且不是null
go3、读入
sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\图片.bmp','where 编号=1','I' --注意条件是 编号=1sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\bb.doc','where 编号=2','I' --注意条件是 编号=2go4、读出成文件
sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\图片.bmp','where 编号=1','O' --注意条件是 编号=1sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\bb.doc','where 编号=2','O' --注意条件是 编号=2
go如果报textcopy不是可执行文件的话,你就到
C:\Program Files\Microsoft SQL Server\MSSQL\Binn
目录下拷备 textcopy.exe到:
C:\Program Files\Microsoft SQL Server\80\Tools\Binn
SqlCommand.CommandText="select Image from pp";
Connection.Open();
SqlDataReader sdr=SqlCommand.ExecuteReader();
int i=0;
while(sdr.Read())
{
byte[] b=(byte[])sdr[0];
MemoryStream ms=new MemoryStream(b,0,b.Length);
Image ima=Image.FromStream(ms);
ima.Save("D:\\xx\\"+(i++).ToString()+".jpg");
ima.Dispose();
}
var
strmFiles : TFileStream;
bedin
strmFiles := TFilestream.create('C:\temp\003.jpg',fmCreate);
TBlobField(query1.fieldbyname('字段名称')).saveToStream(strmFiles);
strmFiles.free;
end; 使用之前要连接数据库:
其中'C:\temp\003.jpg'为你保存的路径和文件名称
query1是TQuery控件
我觉得二进制数据更好一些其实这个要看客户端是什么模式 如果是B/S当然是 保存路径了
要是C/S还是二进制比较号
-- 这种方式以二进制流方式保存到数据库中,文件的读取和保存直接来源于数据库,
-- 在读取和保存时相对较慢,因为中间需要和二进制流进行相互转换.
-- 数据库文件相对较大,存取数据量较大,存储比较占数据库空间.
-- 但是这种方式比较安全,便于管理和维护,
-- 对于图片的操作,如复制,转移等都很方便和快捷.
一种是保存图片路径.
-- 存取数据量小,读取速度较快,
-- 但是这种实体和文件分离的方式,服务器端还的有文件夹来保存这些图片(上传),
-- 所以一旦文件夹不小心丢失,所有图片就找不回了.例子上面已经给了很多了,
这里例一个C#的,参考 :)
.NET在SQL Server中的图片存取技术
http://www.cnblogs.com/stewen/archive/2005/12/20/300587.html