Re: Insert into Image field
From: oj (nospam_ojngo_at_home.com)
Date: 02/05/05
- Next message: Dean: "Re: Indexing..... Which one will use...."
- Previous message: oj: "Re: WMI methods availabe for SQL Server??"
- In reply to: Emma: "Insert into Image field"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 5 Feb 2005 00:09:49 -0800
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 "Emma" <Emma@discussions.microsoft.com> wrote in message news:B9F0A281-E9E1-47C4-A045-901156484760@microsoft.com... >I am reading a binary data from file and I want to insert it into an image > field as follows: > Insert INTO TableName (IDField, Imagefield). I get an incorrect syntax > when > I do this. How do I resolve it? > > Thanks
- Next message: Dean: "Re: Indexing..... Which one will use...."
- Previous message: oj: "Re: WMI methods availabe for SQL Server??"
- In reply to: Emma: "Insert into Image field"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|