Search This Blog

Friday, April 23, 2010

How to resize an image.

C#

Sometimes we want to save an image of a given dimension.
Below method 'resizeImage' is to resizing the image 'imgToResize' for a given size 'size'

private static Image resizeImage(Image imgToResize, Size size)
{


int destWidth = size.Width;
int destHeight = size.Height ;

Bitmap b = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage((Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
g.Dispose();

return (Image)b;
}


The above method can be utilized as -

Image imgOriginal = new Image.FromFile(imgFilePath);
Image imgResized = this.resizeImage(imgOriginal , new Size(100,100));

imgResized.Save(SaveToFilepath);

Now for any size of original image we will get an image of size 100 * 100.

Friday, April 16, 2010

Exception: Invalid attempt to call FieldCount when reader is closed.

Exception: "Invalid attempt to call FieldCount when reader is closed"

Cause: When you attempt to bind data to a control within RowCreated event of a gridview.

Solution: Bind data to a control within RowDataBound event of a gridview instead of RowCreated event.

Wednesday, April 7, 2010

Exception has been thrown by the target of an invocation:GridView

"Exception has been thrown by the target of an invocation" exception come when any datafield of a gridview does not belong to its datasource.

Tuesday, April 6, 2010

How to find highest and second highest value of a column in a table

Using below sql query we can find highest and second highest column value of table.
1- Highest
SELECT sal FROM emp e WHERE 1=(SELECT count(*) FROM emp WHERE e.sal <= sal)

2- Second Highest
SELECT sal FROM emp e WHERE 1=(SELECT count(*) FROM emp WHERE e.sal < sal)

Friday, April 2, 2010

How to restore a MSSQL Database

Step 1:
RESTORE FILELISTONLY
FROM DISK = 'D:BackUpYourBaackUpFile.bak'

Step 2:
RESTORE DATABASE YourDB
FROM DISK = 'D:BackUpYourBaackUpFile.bak'
WITH MOVE 'YourMDFLogicalName' TO 'D:DataYourMDFFile.mdf',
MOVE 'YourLDFLogicalName' TO 'D:DataYourLDFFile.ldf'

Tuesday, March 30, 2010

How do I open a new browser window?

To open a new browser window, use the window.open() method.
For example, the following code opens this page in a new window.

myRef = window.open(''+self.location,'mywin',
'left=20,top=20,width=500,height=500,toolbar=1,resizable=0');



The general syntax of the window.open() method is as follows:

winRef = window.open( URL, name [ , features [, replace ] ] )


The return value, stored in the variable winRef,
is the reference to your new window. You can use this reference later,
for example, to close this window (winRef.close()),
give focus to the window (winRef.focus()) or perform other
window manipulations.



The parameters URL, name, features, replace
have the following meaning:











URL

String specifying the location of the Web page to be displayed in the new window.
If you do not want to specify the location, pass an empty string as the URL
(this may be the case when you are going to write

some script-generated content to your new window).

name

String specifying the name of the new window.
This name can be used in the same constructions as the frame name provided
in the frame tag within a frameset <FRAME NAME=name ...>.
For example, you can use hyperlinks of the form
<a target=name href="page.htm">,
and the hyperlink destination page will be displayed in your new window.



If a window with this name already exists, then
window.open() will display the new content in that existing window,
rather than creating a new one.


features

An optional string parameter specifying the features of the new window.
The features string may contain one or more

feature=value pairs separated by commas.

replace

An optional boolean parameter. If true, the new location will replace
the current page in the browser's navigation history.
Note that some browsers will simply ignore this parameter.






The following features are available in most browsers:














toolbar=0|1

Specifies whether to display the toolbar in the new window.


location=0|1

Specifies whether to display the address line in the new window.



directories=0|1

Specifies whether to display the Netscape directory buttons.


status=0|1

Specifies whether to display the browser status bar.


menubar=0|1

Specifies whether to display the browser menu bar.


scrollbars=0|1

Specifies whether the new window should have scrollbars.


resizable=0|1

Specifies whether the new window is resizable.


width=pixels


Specifies the width of the new window.


height=pixels

Specifies the height of the new window.


top=pixels


Specifies the Y coordinate of the top left corner of the new window.
(Not supported in version 3 browsers.)


left=pixels

Specifies the X coordinate of the top left corner of the new window.
(Not supported in version 3 browsers.)

How to find Multiple connections to various databases on your SQL Server

SELECT distinct b.name
FROM master.dbo.sysprocesses a, master.dbo.sysdatabases b
WHERE b.dbid = a.dbid
AND a.uid = USER_ID(USER)