Saturday, March 28, 2009

SQLDataReader and DataSet

In terms of memory, We always say that we should avoid use of DataSet unless it is very much required. If the requirement can be accomplished with SQLDataReader never use DataSet.

The common answer which we know is DataSet takes more memory than SQLDataReader.

I thought why not find out how much more memory DataSet consumes than SQLDataReader. I ran CLR profiler and I found significant difference between two.

DataSet take 60% more memory than SQLDataReader.

I just created object of SQLDataReader( SqlDataReader dr = new SqlDataReader();), the memory consumption is 22,218 bytes.

And when I created objet of DataSet (DataSet ds = new DataSet();) , the memory consumption is 35,920 bytes.


Use DataSet carefully :)

Happy Coding :)


SQL 2008 Date

SQL 2000 and 2005 don't have option to enter only date in DateTime column. Even if we don't provide time while inserting date in DateTime column, it enters the date along with time like the below screen shot.




SQL 2008 has the feature to store only date, as it has the datatype of Date only rather tahn DateTime.

DECLARE @datetest DATE
SELECT @datetest = '3/28/2009'
SELECT @datetest as [Date]

Output:

Date
----------
2009-03-28

Monday, March 23, 2009

SQL Database information

SQL Server with plenty of databases. Get the space occupied, the location of data and log etc of each database.

Change the execute mode to Text






Execute the below query you will get all the databases name in the result pane

select 'sp_helpdb ' + name + '' + CHAR(10) + 'go' from sysdatabases



The output will be





Copy the above output and execute you will get the details about all the database at one shot.

Friday, March 20, 2009

Latest AjaxControlToolKit

Download Latest AjaxControlToolkit from the below location

http://www.codeplex.com/pks/Release/ProjectReleases.aspx?ReleaseId=16812"

Happy Coding :)

ComboBox set font style


Fill Combo with the available fonts in the system

public void fillFontCombo()
{
FontFamily[] families = FontFamily.Families;
//Loop Through System Fonts
foreach (FontFamily family in families)
{
//Set Current Font's Style To bold
FontStyle style = FontStyle.Bold;
//These Are Only Available In Italic, Not In "Regular",
//So Test For Them, Else, Exception!!
if (family.Name == "Monotype Corsiva" || family.Name == "Brush Script MT"
|| family.Name == "Harlow Solid Italic" || family.Name == "Palace Script MT" ||
family.Name == "Vivaldi")
{
//Set Style To Italic, To Overt "Regular" & Exception
style = style | FontStyle.Italic;
}
Font FCFont = new Font(family.Name, 10, style, GraphicsUnit.Point);
//Display The Font Combo Items
comboBox1.Items.Add(FCFont.Name);
}
comboBox1.SelectedIndex = 1;
}



Add drawitem eventhandler for the combobox to paint the combobox

private void combobox1_drawitem(object sender, DrawItemEventArgs e)
{
//If the index is invalid, do nothing and exit.
if (e.Index == -1 || e.Index >= comboBox1.Items.Count)
return;
//Draw the background of the item.
e.DrawBackground();
// Draw the focus rectangle
if ((e.State & DrawItemState.Focus) != 0)
e.DrawFocusRectangle();
Brush b = null;
try
{
// Create Background Brush.
b = new SolidBrush(e.ForeColor);
// Draw the item.
FontStyle style = FontStyle.Bold;
string strfont = comboBox1.Items[e.Index].ToString();
if (strfont == "Monotype Corsiva" || strfont == "Brush Script MT"
|| strfont == "Harlow Solid Italic" || strfont == "Palace Script MT"
|| strfont == "Vivaldi")
{
//Set Style To Italic, To Overt "Regular" & Exception
style = style | FontStyle.Italic | FontStyle.Regular;
}

Font nfont = new Font(strfont, 10, style);
e.Graphics.DrawString(
strfont,
nfont,
b,
e.Bounds
);

} // End try
finally
{
// Dispose the brush
if (b != null)
b.Dispose();
b = null;
} // End finally
}


Happy Coding :)

Site Meter