A lost bet — Response.BinaryWrite Spoils the day!


Two days ago I lost a bet. My friend Jubair was generating a bar code image and he said how can I get it to display on the page without saving it as a file and giving its source to the image tag. I said you can’t do it because I thought it would be possible in desktop applications only. So we made a deal that if I lose I will write a blog entry for him. So here it is. Anyways, he did it in a manner similar to this one.

dim omemorystream as new memorystream()
img1.save(omemorystream,imagetype)
Response.binarywrite(omemorystream.Buffer)

how to convert an integer to string and left pad it with zero’s?


Here’s a quick and simple way of converting an integer to string (varchar) and left pad it with leading zeros like 00012. This example will get the result in 5 digits

select right(‘00000’ + cast(yourfield as varchar(5)), 5)