|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 12:47 AM
Points: 53,
Visits: 296
|
|
Dear All
I am working in University Project.I have 10000 students physical photos in one directory in corresponding register number file name.My requirement is i want upload all the photos in sqlserver database without using front end.I want details like file name should be store separate column and image store in binary format.
sno registerno Image
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Yesterday @ 2:33 PM
Points: 8,620,
Visits: 8,261
|
|
vs.satheesh (1/8/2013) Dear All
I am working in University Project.I have 10000 students physical photos in one directory in corresponding register number file name.My requirement is i want upload all the photos in sqlserver database without using front end.I want details like file name should be store separate column and image store in binary format.
sno registerno Image
You question has nowhere near enough details for anybody to provide much assistance. If you are really need to store the images in the database I would highly recommend NOT storing them in a table with other information. I would make a table for nothing but those images and a foreign key.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Moden's splitter.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 6:12 AM
Points: 11,645,
Visits: 27,741
|
|
don't arbitrarily remove an application or code from doing the work for you; that is what they are designed to do.
the code to upload the images/blobs in a programming language(the front end you seem to want to arbitrarily avoid) is very compact and easy to understand.
a pure TSQL solution will be huge, involve a cursor calling xp_commandshell and will either require the files exist on the server or in a network location that the SQL service has access to , and that is an extra level of headaches.
A CLR solution like http://nclsqlclrfile.codeplex.com would work here as well, but would encounter the same access issues (file on server or a network share that the service has access to)
google can point you to some programming code in the language of your choice to do the work for you in about 20 lines of code total.
Lowell
--There is no spoon, and there's no default ORDER BY in sql server either. Actually, Common Sense is so rare, it should be considered a Superpower. --my son
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Yesterday @ 10:06 PM
Points: 5,
Visits: 201
|
|
Here is one approach for converting images into table columns with SQL.
This assumes that: - you have a table with an identification that can be tied to the image file name, and - the table has a BLOB column to store the file binary in, and - this is just a data conversion process (I don't think I'd use this in production).
Hope it helps.
/* Import file binary into Columns in SQL tables
The Process: Creates a sample student temp table Builds a cursor set of all student records Iterates the cursor Building dynamic SQL to load the image into the student record, and Executing the dynamic SQL Cleans-up the cursor Removes the temp table */
/* Example student table... replace the table/column names below */ Create TABLE #StudentTable (StudentID Int, FileImage image) Insert Into #StudentTable Select 3708,NULL UNION Select 3709,NULL UNION Select 3710,NULL
/* now setup the necessary variables and create the cursor. */ Declare @StudentID int /* the identifier of the record to be updated with the bin */ Declare @FileImagePath nVarChar(255) = 'C:\Temp\' /* the location of the source files (SQL must have access) */ Declare @RunMe nVarChar(Max) /* the dynamic SQL to load the image file */
DECLARE workCursor CURSOR FOR Select StudentID, @FileImagePath + 'IMG_' + Cast(StudentID as nVarChar(128)) + '.JPG' as FileName /* you will need to change this to your file name pattern */ From #StudentTable Where FileImage is null /* remove this if overwriting pictures is ok */ Order By StudentID
/* open (run the query) the cursor and get the first row's contents into working variables */ OPEN workCursor FETCH NEXT FROM workCursor INTO @StudentID, @FileImagePath
WHILE @@FETCH_STATUS = 0 Begin
Set @RunMe = ' Update #StudentTable Set FileImage = ( Select * From openrowset(BULK '''+ @FileImagePath + ''', SINGLE_BLOB) ToLoad ) where StudentID = ' + Cast(@StudentID as nVarChar (10))
Exec (@RunMe)
FETCH NEXT FROM workCursor INTO @StudentID, @FileImagePath End
/* clean up the cursor after use */ CLOSE workCursor DEALLOCATE workCursor
Select * From #StudentTable
Drop TABLE #StudentTable
Steve Pirazzi ONEWARE, Inc. http://www.oneware.com
Steve Pirazzi ONEWARE, Inc. http://www.ONEWARE.com
|
|
|
|