From: Dooza on
Dave Anderson wrote:
> Dooza wrote:
>> I have gone for a temporary solution, as it seems that as soon as you
>> do a length check or isnull check on the binary field it becomes
>> unusable.
>> I have used this in my SQL view:
>>
>> CASE WHEN (MC.mct_photo IS NULL)
>> THEN '0' ELSE '1' END AS PhotoCheck
>>
>> And this on my page:
>>
>> If rsMotor("PhotoCheck") = 1 Then
>> 'Insert Photo
>> Params = "x=337; y=408; scalex=.33; scaley=.33"
>> Set SigImage = Doc.OpenImageBinary(rsMotor("Photo").Value)
>> Page.Canvas.DrawImage SigImage, Params
>> End if
>>
>> Does anyone have any experience with using binary data in asp? Am I
>> right in thinking that the starting position has changed due to the
>> length check? Is there a way to reset the starting position?
>
> Rather than checking for NULL, use DATALENGTH:
> http://msdn2.microsoft.com/en-us/library/ms173486.aspx

Hi Dave, thats a new one on me, is it SQL only, or can I use it in
ASP/VBScript?

Steve
From: Dave Anderson on
Dooza wrote:
>>> CASE WHEN (MC.mct_photo IS NULL)
>>> THEN '0' ELSE '1' END AS PhotoCheck
>>
>> Rather than checking for NULL, use DATALENGTH:
>> http://msdn2.microsoft.com/en-us/library/ms173486.aspx
>
> Hi Dave, thats a new one on me, is it SQL only, or can I use
> it in ASP/VBScript?

It's only VBScript if you can find it here:
http://msdn2.microsoft.com/en-us/library/d1wf56tt.aspx

The link I provided is Transact-SQL. I meant for you to understand that you
can use it in this manner:

SELECT
MC.mct_photo,
DATALENGTH(MC.mct_photo) AS Bytes,
...
FROM [Your Table]

This does not require a conditional evaluation in the database. You will be
using one, regardless, in your web script, so why add another?



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.


From: Anthony Jones on
"Dooza" <steveNO(a)SPAM.dooza.tv> wrote in message
news:%235Ob1KtgIHA.4376(a)TK2MSFTNGP05.phx.gbl...
> Dooza wrote:
> > Jon Paal [MSMD] wrote:
> >>
http://databases.aspfaq.com/database/how-do-i-prevent-nulls-in-my-database-from-mucking-up-my-html.html
> >>
> >>
> >> http://databases.aspfaq.com/database/coalesce-vs-isnull-sql.html
> >
> > Hi Jon,
> > Thanks for the pointers, I like the idea of doing it in SQL, as I am
> > already using a view to get the data to the page.
> >
> > I am still open to other ideas.
> >
> > Cheers,
> >
> > Steve
>
> I have gone for a temporary solution, as it seems that as soon as you do
> a length check or isnull check on the binary field it becomes unusable.
>
> I have used this in my SQL view:
>
> CASE WHEN (MC.mct_photo IS NULL)
> THEN '0' ELSE '1' END AS PhotoCheck
>
> And this on my page:
>
> If rsMotor("PhotoCheck") = 1 Then
> 'Insert Photo
> Params = "x=337; y=408; scalex=.33; scaley=.33"
> Set SigImage = Doc.OpenImageBinary(rsMotor("Photo").Value)
> Page.Canvas.DrawImage SigImage, Params
> End if
>
> Does anyone have any experience with using binary data in asp?

Yes

>Am I right in thinking that the starting position has changed due to the
> length check?

Yes

> Is there a way to reset the starting position?

No

When using a foward only recordset once you have consumed a BLOB you can't
consume it again. Additional you can't access standard fields once you've
started reading a BLOB.

Therefore you should use DATALENGTH as Dave suggests but you should move it
and any other fields you need to the beginning of the set of fields and
leave the photo data field as the last field. Do not attempt to use any of
the fields after consuming the photo.

Note also that DATALENGTH returns null if the field passed to it as a
parameter is null so you'll need to test that field with IsNull in VBScript
code.

--
Anthony Jones - MVP ASP/ASP.NET


From: Dooza on
Dave Anderson wrote:
> The link I provided is Transact-SQL. I meant for you to understand
that you
> can use it in this manner:
>
> SELECT
> MC.mct_photo,
> DATALENGTH(MC.mct_photo) AS Bytes,
> ...
> FROM [Your Table]
>
> This does not require a conditional evaluation in the database. You
will be
> using one, regardless, in your web script, so why add another?

That makes perfect sense and works perfectly too. It will also allow me
to keep an eye on the size of images in the table.

Thanks again!

Steve
From: Dooza on
Anthony Jones wrote:
> "Dooza" <steveNO(a)SPAM.dooza.tv> wrote in message
> news:%235Ob1KtgIHA.4376(a)TK2MSFTNGP05.phx.gbl...
>> Dooza wrote:
>>> Jon Paal [MSMD] wrote:
> http://databases.aspfaq.com/database/how-do-i-prevent-nulls-in-my-database-from-mucking-up-my-html.html
>>>>
>>>> http://databases.aspfaq.com/database/coalesce-vs-isnull-sql.html
>>> Hi Jon,
>>> Thanks for the pointers, I like the idea of doing it in SQL, as I am
>>> already using a view to get the data to the page.
>>>
>>> I am still open to other ideas.
>>>
>>> Cheers,
>>>
>>> Steve
>> I have gone for a temporary solution, as it seems that as soon as you do
>> a length check or isnull check on the binary field it becomes unusable.
>>
>> I have used this in my SQL view:
>>
>> CASE WHEN (MC.mct_photo IS NULL)
>> THEN '0' ELSE '1' END AS PhotoCheck
>>
>> And this on my page:
>>
>> If rsMotor("PhotoCheck") = 1 Then
>> 'Insert Photo
>> Params = "x=337; y=408; scalex=.33; scaley=.33"
>> Set SigImage = Doc.OpenImageBinary(rsMotor("Photo").Value)
>> Page.Canvas.DrawImage SigImage, Params
>> End if
>>
>> Does anyone have any experience with using binary data in asp?
>
> Yes
>
>> Am I right in thinking that the starting position has changed due to the
>> length check?
>
> Yes
>
>> Is there a way to reset the starting position?
>
> No
>
> When using a foward only recordset once you have consumed a BLOB you can't
> consume it again. Additional you can't access standard fields once you've
> started reading a BLOB.
>
> Therefore you should use DATALENGTH as Dave suggests but you should move it
> and any other fields you need to the beginning of the set of fields and
> leave the photo data field as the last field. Do not attempt to use any of
> the fields after consuming the photo.

Putting the Blob field at the end of the table and the end of my view
was the one thing I did know about Blobs, which is why I guessed that it
was the starting position that was my problem.

I have put the Datalength field just before the Blob.

> Note also that DATALENGTH returns null if the field passed to it as a
> parameter is null so you'll need to test that field with IsNull in VBScript
> code.

Perfect, I have used a NOT ISNULL to display the blob.

Thanks again!

Steve
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: Error with to create my dll component iis 6
Next: GetRows