The following code can be called in the Page Load Event. the Code given here will be displayed from the (x,y) position (0,0). If the pie chart to be drawn from the top of the page, then the following code is OK. If it is need to be created in the center of the page or on the fly means, create a new aspx page and copy the code in the page load event and pass the aspx file as source for an image tag.

Add the following Namespaces

using System.Drawing;

using System.Drawing.Imaging;

using System.Drawing.Drawing2D;

ArrayList aMonths;

ArrayList aProfits;

protected void Page_Load(object sender, EventArgs e)

{

LoadData();

DrawBarChrt("Bar Chart", aMonths, aProfits);

}

//Creating Array for Months and Profits - to populate values for the Report

private void LoadData()
{

aMonths = new ArrayList();
aProfits = new ArrayList();

aMonths.Add("January");
aMonths.Add("February");
aMonths.Add("March");
aMonths.Add("April");
aMonths.Add("May");
aMonths.Add("June");
aMonths.Add("July");
aMonths.Add("August");
aMonths.Add("September");
aMonths.Add("October");
aMonths.Add("November");
aMonths.Add("December");

aProfits.Add(240500);
aProfits.Add(220950);
aProfits.Add(283500);
aProfits.Add(340000);
aProfits.Add(325750);
aProfits.Add(123456);
aProfits.Add(235621);
aProfits.Add(345235);
aProfits.Add(290451);
aProfits.Add(152345);
aProfits.Add(653456);
aProfits.Add(785620);
}

private void DrawBarChrt(String sTitle, ArrayList aMonth, ArrayList aProfit)

{

const int iBarWidth = 30;
const int iBarGap = 20;
const int iMaxHeight = 400;
const int iHeightSpace = 25;
const int iLegendSpace = 30;
const int iTitleSpace = 50;

int iMaxWidth = (iBarWidth + iBarGap) * aMonth.Count + iBarGap;
int iMaxColHeight = 0;
int iTotalHeight = iMaxHeight + iLegendSpace + iTitleSpace;

Bitmap objBitmap = new Bitmap(iMaxWidth, iTotalHeight);
Graphics objGraphics = Graphics.FromImage(objBitmap);

objGraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, iMaxWidth, iTotalHeight);

objGraphics.FillRectangle(new SolidBrush(Color.Lavender), 0, 0, iMaxWidth, iMaxHeight);

// find the maximum value

foreach (int iValue in aProfit)
{

if (iValue > iMaxColHeight)
iMaxColHeight = iValue;

}

int iBarX = iBarGap;
Double iCurrentHeight = 0;
SolidBrush objBrush = new SolidBrush(Color.FromArgb(70, 20, 20));
Font fontLegend = new Font("Arial", 11);
Font fontValues = new Font("Arial", 8);
Font fontTitle = new Font("Arial", 24);

// loop through and draw each bar

for (int iLoop = 0; iLoop <= aMonth.Count - 1; iLoop++)


{


iCurrentHeight = ((Convert.ToSingle(aProfit[iLoop]) / Convert.ToSingle(iMaxColHeight)) * Convert.ToSingle(iMaxHeight - iHeightSpace));



objGraphics.FillRectangle(objBrush, Convert.ToSingle(iBarX), Convert.ToSingle(iMaxHeight - iCurrentHeight), Convert.ToSingle(iBarWidth), Convert.ToSingle(iCurrentHeight));



objGraphics.DrawString(aMonth[iLoop].ToString().Substring(0, 3) , fontLegend, objBrush, Convert.ToSingle(iBarX), Convert.ToSingle(iMaxHeight));



objGraphics.DrawString(String.Format(aProfit[iLoop].ToString(), "#,###"), fontValues, objBrush, Convert.ToSingle(iBarX), Convert.ToSingle(iMaxHeight - iCurrentHeight - 15));



iBarX += (iBarGap + iBarWidth);

}



objGraphics.DrawString(sTitle, fontTitle, objBrush, Convert.ToSingle((iMaxWidth / 2) - sTitle.Length * 6), Convert.ToSingle(iMaxHeight + iLegendSpace));


//objBitmap.Save("C:\inetpub\wwwroot\graph.gif", ImageFormat.GIF)


objBitmap.Save(Response.OutputStream, ImageFormat.Gif);
objGraphics.Dispose();
objBitmap.Dispose();

}

The output is like this :

Category : | Read More......

The following code can be called in the Page Load Event. the Code given here will be displayed from the (x,y) position (0,0). If the pie chart to be drawn from the top of the page, then the following code is OK. If it is need to be created in the center of the page or on the fly means, create a new aspx page and copy the code in the page load event and pass the aspx file as source for an image tag.

Add the following NameSpace

using System.Drawing;

using System.Drawing.Imaging;

using System.Drawing.Drawing2D;

int startAngle = 0;

int sweepAngle = 45;

const int width = 500, height = 500;

Response.ContentType = "image/jpeg";

Bitmap objBitmap = new Bitmap(width, height);

Graphics objGraphics = Graphics.FromImage(objBitmap);

// Create a black background for the border

objGraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, width, height);

//To Draw pie chart

SolidBrush objBrush = new SolidBrush(Color.Aqua);

objGraphics.SmoothingMode = SmoothingMode.Default;

Random rand = new Random();

//Loop through 180 back around to 135 degress so it gets drawn correctly.

for(int iLoop = 0;iLoop<= 315;iLoop += 45)

{

startAngle = (iLoop + 180) % 360;

objBrush.Color = Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255));

objGraphics.FillPie(objBrush, 50, 50, 300, 300, startAngle, sweepAngle);

}

// Save the image to a file

objBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);

// clean up...

objGraphics.Dispose();

objBitmap.Dispose();

The Output is like this:

Category : | Read More......

Resource File :

• Resource Files are most beneficial while developing multilingual Web applications
• A resource file is a XML file that contains the strings that we want to
a. Translate into different languages.
b. Can be updated dynamically so that user themselves can modify values in resource files once the application is deployed on the server without re-compiling the entire application itself.

• The resource file contains key / value pairs.
• Each pair is an individual resource.
• Key names are not case sensitive.

Types of Resources:

There are 2 types of Resource files :

1.Global Resource file :

This file is present in a specialized folder called /App_GlobalResources, located at the root of the application. All pages, user-controls, etc. can access these resources, so they typically are used as shared resources. The resources which should be available throughout the application are stored in this file.

2.Local Resource file :

These files are present in /App_LocalResources folder. These files follow the naming convention of the associated page, user-control, or master-page, along with the culture definition. These files are only accessible by the associated page.

Sample Code for Resource File :

I Created four label and one dropdown and based on the dropdown selection the language should change. I Created three resource files for English, French and Tamil. In Name Column [Key] I give the Control Name and the Value Column [Value] I give the Text to be displayed.

//To get the Default Language from the browser.
strDefaultLang = Request.Headers["Accept-Language"].Split(',')[0].Trim();

//To specify the Language to be displayed.
if(ddlLanguage.SelectedItem.Text == "English")
strDefaultLang = "en-us";
else if(ddlLanguage.SelectedItem.Text == "Tamil")
strDefaultLang = "ta-IN";
else if (ddlLanguage.SelectedItem.Text == "French")
strDefaultLang = "fr-FR";


//To set the Language for the Control to displayed:

System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(Convert.ToString(strDefaultLang).ToLower());
lblAddress1.Text = Resources.Language.lbladdress1;
lblAddress2.Text = Resources.Language.lbladdress2;
lblName1.Text = Resources.Language.lblname1;

lblName2.Text = Resources.Language.lblname2;

Language is the name of the Resource file name and the Key name entered in the resource file are populated automatically. Select the key name to populate the value for the control.

The Resource file Name should be unique. the file name in this scenario is Language.resx for default Language [English]. Language.fr.resx for French, Language.ta.resx for Tamil.

Category : | Read More......


  • The maximum number of columns per base table is 1024.

  • The maximum number of columns per index is 16.

  • The maximum number of columns per SELECT statement is 4096.

  • The maximum number of foreign key table references per table is 253.

  • The maximum number of parameters per stored procedure is 1024.

  • The maximum number of characters allowed for a table name is 128.

  • The maximum number of characters allowed for a column name 128.

  • The maximum number of columns in the view is 250.

Tables which are created in TempDB Database instead of creating in the actual database is considered as Temporary Tables. It will be automatically deleted once the connection is closed or if the server is stopped/restarted. Temporary tables doesn't locate in our actual database inturn created and function from tempdb database. To reduce the number of rows for joins, to aggregate data from different sources, or to replaces cursors and for parameterized views, we will use Temporary tables.

There are two kinds of Temporary Tables:

1. Local Temporary Table
2. Global Temporary Table

Local Temporary Table:

Tables whose accessibility is specific only to the scope of temporary table declaredis considered as Local temporary tables. Local Temporary tables exists until specific user connection exists/until the server is restarted. If User1 have created a table #A another user can create a temporary table #A so that, each user can create their own user specific temporary tables. Local Temporary table can be specified with # symbol before the table name.Am Creating a SP with Temporary table(named #LocalTempTable) creation inside the SP,

Create procedure usp_proc1
as
Begin
create table #Temp (ID int,[Name] char(30) )
insert into #Temp values (1,'Venkat')
End


Am Creating another SP Which calls the above created Temporary table(#LocalTempTable)

Create procedure usp_proc2
as
Begin
select * from #Temp
End


Now, i am trying to executing the first Stored Procedure

exec usp_proc1

A Temporary table is created and now i am trying to execute the Second SP,

exec usp_proc2

Am gettting an error "Invalid object name '#LocalTempTable'." Its because the local temporary table created in the first SP is specific only to it and it cant be accessed by another SP.

Global Temporary Table:

Tables whose accessibility is global to all the users in the database were come under global temporary table. Global Temporary table exists until the last connection exists/until the server is restarted. Global Temporary table can be specified with ## symbol before the table name.
Am Creating SP with Temporary table(named ##GlobaTempTable) creation inside the SP,

Create procedure usp_proc3
as
Begin
Create table ##Temp (ID int,[Name] char(30) )
Insert into ##Temp values (1,'Venkat')
End


Creating another SP Which calls the above created Temporary table(#GlobalTempTable)

Create procedure usp_proc4
as
Begin
Select * from ##Temp
End

Now, i am trying to executing the first Stored Procedure

exec usp_proc3

Global Temporary table is created and now i am trying to execute the Second SP,

exec usp_proc4

It will display the result as "1" "Venkat"

Limitations and Alternative for Temporary Table

Temporary tables created in TempDB will create additional overheads because of huge resource utilization. The best alternative for temporary table is creating table variables, which reside only in memory instead of creating in TempDB and it will use less resources when compare to Temporary tables.

Tables which can be declared and functions similar to a varaible are referred as Table Variables.

Table variables were created in memory inturn enable faster database access. Table variables are considered as good alternative for Temporary tables. Since, temporary tables will create tables in TempDB, there is additional resource utilization in accessing TempDB and Creating tables in TempDB.

Terms and Conditions in using variables:

Unlike temporary tables, table variables adhere to its scope. Temporary tables can be created first and we can execute insert statement or dml operations seperately inside the scope. For example, #a is executed first and afterwards we can execute dml operations subsequently since its stored in database we can use it. Where as, table varaibles resides in memory and doesn't have physical structure, the declaration statement and dml statements should be executed simultaneously else if we try to execute declare statement first(executed) and afterward if we try to access that table an error will be thrown indicating table is not available.

Declaring a table variable:

DECLARE tablevariable-name TABLE ( COLUMN1 TYPE, COLUMN2 TYPE, COLUMN3 TYPE, .....)

Example : declare @TableVariable table(id int,name varchar(20))

All the DML Operations are similar to the Table.

insert into @TableVariable values(1,'Microsoft')

select * from @TableVariable

select * from Table inner join @TableVariable on Table.id= @TableVariable.id

To Trim the Empty space on both side

String.prototype.trim = function() {return this.replace(/^\s+\s+$/g,"");}

//Checking Blank Values

if (document.getElementById("txtName").value.trim()=="")
{
alert("Name Field can not be blank");
document.getElementById("txtName").focus();
return false;
}

//Checking AlphaNumeric Values

if (CheckKeyIsAlphanumerics(document.getElementById(txtName)))
return false;
else
return true;

function CheckKeyIsAlphanumerics(str)
{
var string = str.value.trim();
var iChars = "01234546789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (var i = 0; i lt; string.length; i++)
{
if (iChars.indexOf(string.charAt(i)) == -1)
return true;
}
return false;
}

To allow special characters in condition means add the special character in the iChars Variable.

//EmailValidation in the Textbox

if (isValidEMailID(document.getElementById("txtEmail")))
return true;
else
return false;


function isValidEMailID(oControl)
{
if(oControl.value != "")
{
if((/([A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}][A-Za-z]\w*(\.[A-Za-z]\w*)+)$/.test(oControl.value))==false)
{
alert("Invalid Email Format.");
oControl.value ="";
return false;
}

}
return true;
}

Pass the Control ID as Parameter for the Function.

Pop-up New Window from Java Script

window.open('Form2.aspx?id=1,value=raja','page1','height=350,width=470,location=no,menubar=no,
resizable=no,scrollbars=yes,toolbar=no');

Form2.aspx - Name of the aspx page to redirectValues can be passed to next page thro query stringCustom size for Height and WidthBased on the need give the menubar, resizable, scrollbars, toolbar display

Changing the Color of the Button in a page

function BtnColorChange()

{

var f = document.getElementById("form1");

var inputs = f.getElementsByTagName("input");


for(var i = 0; i < inputs.length; i++)
{
if(inputs[i].type == "submit")
inputs[i].style.color = '#C9C5C5';
}

}

JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Firefox, Chrome, Opera, and Safari.

What is JavaScript?

* JavaScript was designed to add interactivity to HTML pages
* JavaScript is a scripting language
* A scripting language is a lightweight programming language
* JavaScript is usually embedded directly into HTML pages
* JavaScript is an interpreted language (means that scripts execute without preliminary compilation)
* Everyone can use JavaScript without purchasing a license

What can a JavaScript do?

JavaScript gives HTML designers a programming tool - HTML authors are normally not programmers, but JavaScript is a scripting language with a very simple syntax! Almost anyone can put small "snippets" of code into their HTML pages

JavaScript can put dynamic text into an HTML page - A JavaScript statement like this: document.write(" + name + ") can write a variable text into an HTML page

JavaScript can react to events - A JavaScript can be set to execute when something happens, like when a page has finished loading or when a user clicks on an HTML element

JavaScript can read and write HTML elements - A JavaScript can read and change the content of an HTML element

JavaScript can be used to validate data - A JavaScript can be used to validate form data before it is submitted to a server. This saves the server from extra processing

JavaScript can be used to detect the visitor's browser - A JavaScript can be used to detect the visitor's browser, and - depending on the browser - load another page specifically designed for that browser

JavaScript can be used to create cookies - A JavaScript can be used to store and retrieve information on the visitor's computer

1. Which of the following data types has the least data type precedence?

A. BIGINT

B. FLOAT

C. DECIMAL

D. MONEY

E. REAL

F. NUMERIC

2. You have a column that will only contain values from 0 to 256. What's the most economical data type to use for the column?

A. TINYINT

B. SMALLINT

C. INT

D. DECIMAL(3)

E. VARCHAR(3)

3. What will be the result of the following statement?

SELECT STR(6365, 3)

A. 6365

B. 6,365

C. 6400

D. 6,400

E. 6365.000

F. ***

4. Which of the following is NOT true about the SMALLDATETIME data type?

A. SQL Server stores SMALLDATETIME values as two 2-byte integers.

B. The first 2 bytes store the number of days after January 1, 1900

C. The second byte store the number of seconds since midnight.

D. Dates range from January 1, 1900 through June 6, 2079.

5. What's the maximum number of rows a table can have in SQL Server 2000?

A. 1,024

B. 65,536

C. 1,073,741,824

D. Limited by available storage

6. What's the minimum value can a TINYINT data type hold?

A. -255

B. -256

C. -512

D. 0

7. What will be the result of the following statement?

SELECT CAST(0 AS DATETIME)

A. 1900-01-01 00:00:00.000

B. 9999-12-31 00:00:00.000

C. 1753-01-01 00:00:00.000

D. 1800-01-01 00:00:00.000

E. 1853-01-01 00:00:00

F. The statement will generate an error. An integer value cannot be converted to a DATETIME data type.

8. What will be the result of the following statement?

SELECT CAST(-1 AS DATETIME)

A. 1900-01-01 00:00:00.000

B. 9999-12-31 00:00:00.000

C. 1753-01-01 00:00:00.000

D. 1800-01-01 00:00:00.000

E. 1853-01-01 00:00:00

F. The statement will generate an error. An integer value cannot be converted to a DATETIME data type.

9. To identify records that were updated in a table from a trigger, which of the following tables need to be investigated?

A. Inserted system table

B. Updated system table

C. Deleted system table

D. Inserted and Deleted system tables

10. Which of the following is a reserved keyword in SQL Server 2000 and therefore cannot be used as an object name or as a column name in a table unless delimited?

A. ADD

B. SUBTRACT

C. MINUS

D. MULTIPLY

E. DIVIDE

F. None of the above is a reserved keyword in SQL Server 2000.

11. Which of the following is NOT true about the PRIMARY KEY constraint?

A. Can be of more than 1 column.

B. Always created as CLUSTERED.

C. Enforces data uniqueness by creating a unique index for the primary key columns.

D. Column that participates in the PRIMARY KEY constraint cannot accept NULL values.

Answers :

1. A

Here is the order of data type precedence of the given options from highest to lowest: FLOAT, REAL, DECIMAL/NUMERIC, MONEY and BIGINT

2. B

A SMALLINT data type uses only 2 bytes of data and can store value from -32,768 to 32,767. A TINYINT data type cannot be used because the maximum value it can hold is 255. Although an INT data type can be used, SMALLINT will use only 2 bytes compared to INT's 4 bytes. VARCHAR(3) will use 3 bytes while DECIMAL(3) will use 5 bytes.

3. F

The STR function returns character data converted from numeric data. The second parameter of the STR function is for the total length of the output, including the decimal point, sign, digits and spaces. When the float expression, specified in the first parameter, exceeds the specified length, the STR function returns * for the specified length.

4. C

A SMALLDATETIME data type is stored in SQL Server as two 2-byte integers. The first 2 bytes store the number of days after January 1, 1900. The other 2 bytes store the number of minutes (not seconds) since midnight. Dates ranges from January 1, 1900 through June 6, 2079, with accuracy to the minute.

5. D

The maximum number of rows that any table in SQL Server 2000 can have is limited by the available storage in the server.

6. D

A TINYINT data type uses only 1 byte of data and only stores values from 0 to 255

7. A

A DATETIME data type is stored internally in SQL Server as two 4-byte integers. The first 4 bytes store the number of days before or after the base date of January 1, 1900. Given this, a value of 0 corresponds to January 1, 1900.

8. F

Arithmetic overflow error converting expression to data type smalldatetime.

9. D

The inserted system table and deleted system table, also known as the magic tables, are used by triggers to place inserted, updated or deleted records in a table. For inserts, the inserted table will contain the newly inserted records. For deletes, the deleted system table will contain the deleted records. For updates, the old values are contained in the deleted system table while the new values are contained in the inserted system table. There is no updated system table.

10. A

Of these list of words, only ADD is a reserved keyword in SQL Server 2000. One of the uses of the ADD is in the ALTER TABLE when adding a new column to a table

11. B

Primary keys are not always created as CLUSTERED indexes. If a table already has an existing clustered index before a PRIMARY KEY constraint is created for the table, adding a PRIMARY KEY constraint on the table will be created as a non-clustered index.

1. What is the best data type to store the birthdays of the US Presidents, starting with George Washington's birthday of February 22, 1732?

A. DATETIME
B. SMALLDATETIME
C. INT
D. VARCHAR

2. Which of the following is NOT true about the TRUNCATE TABLE command?

A. Removes all records from the table.
B. Resets the identity column to the seed of the column.
C. Delete triggers are executed.
D. It cannot be used on tables referenced by foreign tables.

3. What will be the value of @TodaysDate in the following script?

DECLARE @TodaysDate DATETIME
SET @TodaysDate = '12/25/2005'
SET @TodaysDate = @TodaysDate + 5

A. 12/25/2010
B. 12/30/2005
C. 04/24/2006
D. An error is generated. You cannot add together a DATETIME value and an INT value.

4. What will be the value of @TodaysDate in the following script?

DECLARE @TodaysDate Varchar(10)
SET @TodaysDate = '12/25/2005'
SET @TodaysDate = @TodaysDate + 5

A. 12/25/2010
B. 12/30/2005
C. 04/24/2006
D. An error is generated. You cannot add together a DATETIME value and an INT value.

5. Which of the following statements is the correct syntax for adding a new column called Gender into a table called dbo.Employees that already contains data?

A. ALTER TABLE dbo.Employees ADD COLUMN Gender CHAR(1) NOT NULL
B. ALTER TABLE dbo.Employees ADD COLUMN GENDER CHAR(1) NULL
C. ALTER TABLE dbo.Employees ADD Gender CHAR(1) NOT NULL
D. ALTER TABLE dbo.Employees ADD Gender CHAR(1) NULL

6. What will be the output of the following statement?

SELECT CHARINDEX('is','Missississippi', -1)

A. 0
B. 2
C. 8
D. -1
E. NULL
F. Statement will generate an error. Only positive integer values are allowed.

7. What will be the output of the following statement?

SELECT CHARINDEX('Missississippi', 'is', -1)

A. 0
B. 2
C. 8
D. -1
E. NULL
F. Statement will generate an error. Only positive integer values are allowed.

8. What's the maximum length that can be specified in an NVARCHAR data type in SQL Server 2000?

A. 2000
B. 4000
C. 8000
D. No Limit

9. What will be the result of the following statement?

SELECT ROUND(123.89, -1)

A. 120.00
B. 123.00
C. 123.90
D. 124.00

10. What's the maximum number of parameters can a SQL Server 2000 stored procedure have?

A. 128
B. 256
C. 512
D. 1,024

Answers :

1. C

The earliest date that can be stored in a DATETIME data type is January 1, 1753 while the earliest date that can be stored in a SMALLDATETIME data type is January 1, 1900 so neither of these data types can be used. Both an INT data type and a VARCHAR data type can be used but between these two data types, the best option is an INT data type where the date value can be stored in the YYYYMMDD format. An INT data type will only use 4 bytes while a VARCHAR data type storing the same date value will need 8 bytes.

2. C

When the contents of a table are removed using the TRUNCATE TABLE command, delete triggers are not executed. Delete triggers are only triggered when the DELETE command is used.

3. B

Adding an INT value to a DATETIME value is like adding that number of days to the DATETIME value. This is similar to using the DATEADD function and passing DD as the first parameter (the datepart parameter).

4. D

Conversion failed when converting the varchar value '12/25/2005' to data type int.

5. D

To add a column to an existing table, the ALTER TABLE command is used with the ADD option (without the word COLUMN). Since there's data on the table already and since no default value has been specified, the column should be created with the NULL option. Otherwise an error will be encountered.

6. B

The CHARINDEX function returns the starting position of the specified expression in a character string. The third parameter of the CHARINDEX functions is the character position to start searching for the first parameter in the second parameter. If the starting location is a negative number, the search starts at the beginning of the second parameter

7. A

8. B

NVARCHAR data types store variable-length Unicode data with a maximum length of 4,000 characters. On the other hand, VARCHAR data types store variable-length non-Unicode data with a maximum of 8,000 characters.

9. A

The ROUND function returns a numeric expression rounded to the specified length or precision. The second parameter of the ROUND function is the precision to which the input numeric expression is to be rounded. When the second parameter is a negative number, the numeric expression is rounded on the left side of the decimal point, as specified in the length.

10. D

The maximum number of parameters a stored procedure in SQL Server can have is 1,024, which is also the maximum number of columns a table can have.