How to get size of an file stored as image in SQL Database

  • Thread starter Thread starter Dino Buljubasic
  • Start date Start date
D

Dino Buljubasic

I want to get the size of a file stored in SQL Database (as image data
type).

Anybody knows how to do this?

Any help will be greatelly appreciated
 
Get data from the database into binary array and calc in't length.
 
No I can not do that. I need the size of image so I can set my
progress bar so it displays how much of that image has been downloaded
so far. If I store it ino an array, then what is point of having
progress bar, the image is already fetched from the database.
 
just to correct my self:

I need this information so I can set my progress bar to show download
progress.

Thank you
 
Dino said:
just to correct my self:

I need this information so I can set my progress bar to show download
progress.

Thank you
Then store the size of the file in the database.

Bob
 
Dino,

You make me curious, I know that I can get an image from a database using a
datareader, using an executescalar, using a dataadapter.

Non of those give me the change to see any progress even when I know how
large the image is.

How do you do that?

Cor
 
I really appreciate help but I don't need help on how to go arround
the problem but how to solve it.

I can not store size to the database because database already exist
with thousants of records in it. I am not in the position to go
throught every record find sizes of images and update the database.

thank you
 
I am using FileStream and BinaryWriter to load the image and write it
to a byte array.

I write chunks of binary data to array in a while loop. At the end I
can get the size of that array but I need the size before I start
downloading it so I can calculate progress inside my progress bar.

Unfortunatelly, creators of the database did not store size of images
saved to database in a column, so I can not fetch that information.

Any Ideas how to solve this?

Thank you, appreciate your help
 
WhatEverYourName is,

I made a piece of code (sample) from your SQLString which test it direct.

\\\
Public Class TestLength
Public Shared Sub Main()
Dim conn As New SqlClient.SqlConnection("Server=(local);" & _
"DataBase=Northwind; Integrated Security=SSPI")
Dim sqlstr1 As String = "SELECT DATALENGTH(Photo) " & _
" FROM Employees WHERE EmployeeID = 3"
Dim sqlstr2 As String = "SELECT Photo FROM Employees WHERE
EmployeeID = 3"
Dim cm As New SqlClient.SqlCommand(sqlstr1, conn)
conn.Open()
Console.Write(cm.ExecuteScalar.ToString & vbCrLf)
cm.CommandText = sqlstr2
Console.Write((DirectCast(cm.ExecuteScalar, Byte()).Length).ToString
& vbCrLf)
conn.Close()
End Sub
End Class
///

Now I still needs to know how Dino does the reading.

Cor
 
HI Cor,

thank you for your help. I fixed the problem and it works just great.
Did not know of DATALENGTH() before, now I learned something new

And it is working great.

I appreciate your help
 
You're welcome.

Dino Buljubasic said:
HI Cor,

thank you for your help. I fixed the problem and it works just great.
Did not know of DATALENGTH() before, now I learned something new

And it is working great.

I appreciate your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top