PDA

View Full Version : cho hoi ve datatype image?



snoopy
27-05-2004, 17:53
Trong sql server 2000 co datatype image cho mình hỏi làm sao để lưu hình ảnh vào trong filed này? Cám ơn..

lam_lvl
29-06-2004, 22:01
Kiểu Image trong SQL Server không phải để dành lưu ..images hay pictures !, bạn nhầm lẫn điều đó ! Nếu bạn muốn lưu image hay picture bạn hãy xác định datatype là : BINARY
Chúc thành công.

snoopy
30-06-2004, 09:10
Dậy thì với kiểu binary thi dùng the nao de luu truc tiep 1 picture vao đó?

KhungHai
23-07-2004, 08:07
Đầu tiên 1 picture sẽ được mã hóa thành các bit nhi phân (binary) để lưu và trong database, sau đó khi muốn truy xuất picture đó thì bạn chỉ việc gán field đó vào trong một image hay picture mà thôi. Còn cách thực hiện làm sao bạn có thể vào một số website hỗ trợ lập trình để tham khảo kỹ thuật này.
Chúc bạn thành công!

duclee
23-07-2004, 12:56
lưu đường dẫn file hình là được gùi, chưa thấy lưu luôn file vào hồi nào ^_^

snoopy
25-07-2004, 22:14
Minh thay uu diem cua viec luu image trong database la khi xoa 1 record thi image do cung duoc xoa luon, hinh nhu chi co may cai COM la co ho tro cai nay thui, con code thi van chua thay!

ivanbalap
30-07-2004, 00:19
Chao cac ban,
Minh cung dang gap rac roi trong van de luu hinh anh vao SQL day.
Hien gio minh dang hien thuc theo cach ma duclee noi, nhung ma lai gap rac roi trong khau backup.
Cac file image cua minh la dang .tif, cac ban co the ho tro minh cach de insert cac file nay vao SQL khong (di nhien la duoi dang binary rui)?
Nhung ma khong biet khi da insert duoc vao sql rui thi show len web nhu the nao nua.
Mong cac ban giup do

oj_n
31-07-2004, 15:13
You can use TextCopy.exe in the \bin folder.

-- OJ: TEXTCOPY example
-- Loading files into db &
-- exporting files out to folder
--

------------------
--TEXTCOPY IN
------------------
--create tb to hold data
create table tmp(fname varchar(100),img image default '0x0')
go
declare @sql varchar(255),
@fname varchar(100),
@path varchar(50),
@user sysname,
@pass sysname

set @user='myuser'
set @pass='mypass'

--specify desired folder
set @path='c:\winnt\'

set @sql='dir ' + @path + '*.bmp /c /b'

--insert filenames into tb
insert tmp(fname)
exec master..xp_cmdshell @sql

--loop through and insert file contents into tb
declare cc cursor
for select fname from tmp

open cc
fetch next from cc into @fname

while @@fetch_status=0
begin
set @sql='textcopy /s"'+@@servername+'" /u"'+@user+'" /p"'+@pass+'"
/d"'+db_name()+'" /t"tmp" /c"img" /w"where fname=''' + @fname + '''"'
set @sql=@sql + ' /f"' + @path + @fname + '" /i' + ' /z'
print @sql
exec master..xp_cmdshell @sql ,no_output
fetch next from cc into @fname
end
close cc
deallocate cc
go
select * from tmp
go
-------------------
--TEXTCOPY OUT
-------------------
declare @sql varchar(255),
@fname varchar(100),
@path varchar(50),
@user sysname,
@pass sysname

set @user='myuser'
set @pass='mypass,'

--specify desired output folder
set @path='c:\tmp\'

set @sql='md ' + @path

--create output folder
exec master..xp_cmdshell @sql

--loop through and insert file contents into tb
declare cc cursor
for select fname from tmp

open cc
fetch next from cc into @fname

while @@fetch_status=0
begin
set @sql='textcopy /s"'+@@servername+'" /u"'+@user+'" /p"'+@pass+'"
/d"'+db_name()+'" /t"tmp" /c"img" /w"where fname=''' + @fname + '''"'
set @sql=@sql + ' /f"' + @path + @fname + '" /o' + ' /z'
print @sql
exec master..xp_cmdshell @sql ,no_output
fetch next from cc into @fname
end
close cc
deallocate cc

set @sql='dir ' + @path + '*.bmp /c /b'
exec master..xp_cmdshell @sql

go
drop table tmp
go

oj_n
31-07-2004, 15:15
Also:

HOWTO: Read and Write BLOBs Using GetChunk and AppendChunk
http://support.microsoft.com/?id=194975

HOWTO: Access and Modify SQL Server BLOB Data by Using the ADO Stream Object
http://support.microsoft.com/?id=258038

linhdpl
05-08-2004, 08:19
Có tiền bối nào rành về SQL, xin gữi cho em một bài giảng về cách lưu trữ cũng như truy xuất dữ liệu kiểu Image.
E-mail của em là: linhdpl@hotmail.com hoặc nguoiyeucongnghe@yahoo.com