How-to randomize in SQL

Few weeks ago I was task to populate dummy data into a table, I have to come up with a price and randomize the ID from 80-90, I have to populate this table with 25000 records!

So for solution, I turned to Rand(), an SQL function that randomizes integer, for quick reference here’s the simple syntax:

Rand [Seed]

a quick example would be :

Then I came up with my own


DECLARE @maxValue tinyint = 80
, @minValue tinyint = 90
, @randomId int
, @hid INT
, @amtadd INT;
SET @hid=0;
SET @amtadd=20;
WHILE @hid < 2000
SET @randomId = Cast(((@maxValue + 1) - @minValue) 
* Rand() + @minValue AS tinyint);
INSERT INTO tblDetail (PaymentId,PaymentDate, PaymentAmount,SeqNumber,IsActive,CreateDate,UpdateDate,UpdateUser)
VALUES (@randomId,'2013-10-17',@amtadd,3,1,getdate(),getdate(),'Alf')
SET @hid = @hid + 1;
SET @amtadd = Cast(((380 + 1) - 120) 
* Rand() + 120 AS int);


And there it is!

The new Visual Studio 2012 RC

2 years ago April 2010, Microsoft released Visual Studio 2010, now we have the RC available for us to play around with.  So what are the most obvious upgrade from the 2010 ? I’ve made few notices on the features.

We’ll start off with the theme, the new VS 2012 sports a new look color and logo was changed from it’s bluish kinda color to total dark look (inspired by the dark knight maybe? ) , the logo was tweaked a little bit also to match the new look.

Inside the hood, there are some important changes such as SQL , ANALYZER (Optimizer) , and ARCHITECTURE.




How to resize image with tranparency in c#

It’s been a while since I did my last tutorial/tips, now I’m back from a long nap of mental dement.

In this tutorial I will show and provide you a way to resize an image with transparency property, a few days back I was working on a project and this project requires me to do cache of images since these images are significantly large.

So without further ado, here it is;

First of I created a class called ImageHandler.cs, this class will have a method called resizeimage(), that has 2 params, savepath and sourcepath. The problem with page is that “Image” control is different from “Drawing.Image” control so you can’t directly get the image value and display on the page, you will need to sort of “cache” the images (save) then access it from your local folder, you can be more elaborate and handle the deletion of folder once session is done. For the purpose of this tutorial I’m just going to share you now the code called resizeImage;

public Image resizeImage(int newWidth, int newHeight, string stImagePath)
Image imgPhoto = Image.FromFile(stImagePath);
int newWidth=imgPhoto.Width * 50/100; int newHeight=imgPhoto.Height * 50/100;
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
//Consider vertical pics
if (sourceWidth < sourceHeight)
int buff = newWidth;
newWidth = newHeight;
newHeight = buff;
int sourceX = 0, sourceY = 0, destX = 0, destY = 0;
float nPercent = 0, nPercentW = 0, nPercentH = 0;
nPercentW = ((float)newWidth / (float)sourceWidth);
nPercentH = ((float)newHeight / (float)sourceHeight);
if (nPercentH < nPercentW)
nPercent = nPercentH;
destX = System.Convert.ToInt16((newWidth -
(sourceWidth * nPercent)) / 2);
nPercent = nPercentW;
destY = System.Convert.ToInt16((newHeight -
(sourceHeight * nPercent)) / 2);
int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);
Bitmap bmPhoto = new Bitmap(newWidth, newHeight,
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
new Rectangle(destX, destY, destWidth, destHeight),
new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
return bmPhoto;

Things to watch out for are these lines:

int newWidth=imgPhoto.Width * 50/100; int newHeight=imgPhoto.Height * 50/100;

In the above line you can pass these values as a parameter, what I did here was to automatically reduce the image size by 50%, you can dictate your height and width by making these as part of your parameters.

The next line of codes below are very important, this is where you set the transparency since Bitmaps do not have transparency in them; make sure you set the color to “transparent” instead of white or black as you would normally on non transparent (png) images.

Graphics grPhoto = Graphics.FromImage(bmPhoto);

And how you access the method would be something like this;

using (System.Drawing.Image newImgFile = (System.Drawing.Image) p.resizeImage(imagetoResize))

your imagetoResize is your image source (path +filename), the trick to making this work is to make sure you have access to the path of your source image file.

And there it is, one more thing to note is to make sure to check if the file exist then skip the saving only when it doesn’t.

Happy coding!