469,304 Members | 1,888 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,304 developers. It's quick & easy.

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

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
Nov 21 '05 #1
13 6814

Get data from the database into binary array and calc in't length.
"Dino Buljubasic" <di**@noplacelikehome.com> wrote in message
news:74********************************@4ax.com...
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

Nov 21 '05 #2

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.

On Wed, 9 Mar 2005 22:12:53 +0300, "gaidar" <ga****@vbstreets.ru>
wrote:

Get data from the database into binary array and calc in't length.
"Dino Buljubasic" <di**@noplacelikehome.com> wrote in message
news:74********************************@4ax.com.. .
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


Nov 21 '05 #3
just to correct my self:

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

Thank you

On Wed, 09 Mar 2005 18:47:53 GMT, Dino Buljubasic
<di**@noplacelikehome.com> wrote:
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


Nov 21 '05 #4
Dino Buljubasic wrote:
just to correct my self:

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

Thank you

On Wed, 09 Mar 2005 18:47:53 GMT, Dino Buljubasic
<di**@noplacelikehome.com> wrote:

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


Then store the size of the file in the database.

Bob
Nov 21 '05 #5
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
Nov 21 '05 #6
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

On Wed, 09 Mar 2005 20:33:48 +0100, Bob Hollness <bo*@blockbuster.com>
wrote:
Dino Buljubasic wrote:
just to correct my self:

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

Thank you

On Wed, 09 Mar 2005 18:47:53 GMT, Dino Buljubasic
<di**@noplacelikehome.com> wrote:

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


Then store the size of the file in the database.

Bob


Nov 21 '05 #7

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

On Wed, 9 Mar 2005 20:35:50 +0100, "Cor Ligthert"
<no************@planet.nl> wrote:
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


Nov 21 '05 #8
SELECT DATALENGTH(imagecolumn) FROM sometable

"Dino Buljubasic" <di**@noplacelikehome.com> wrote in message
news:74********************************@4ax.com...
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

Nov 21 '05 #9
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
Nov 21 '05 #10
Look at using CommandBehavior.SequentialAccess along with DataReader.
"Cor Ligthert" <no************@planet.nl> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
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

Nov 21 '05 #11
WhateverName,

Thanks

Cor
Nov 21 '05 #12
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

On Thu, 10 Mar 2005 09:13:57 +0100, "Cor Ligthert"
<no************@planet.nl> wrote:
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


Nov 21 '05 #13
JD
You're welcome.

"Dino Buljubasic" <di**@noplacelikehome.com> wrote in message
news:5m********************************@4ax.com...
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

On Thu, 10 Mar 2005 09:13:57 +0100, "Cor Ligthert"
<no************@planet.nl> wrote:
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

Nov 21 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mike | last post: by
5 posts views Thread by Philippe Martin | last post: by
4 posts views Thread by Jarry | last post: by
3 posts views Thread by =?Utf-8?B?ZGF2aWQ=?= | last post: by
3 posts views Thread by Christoph Burschka | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.