Thursday, September 13, 2007

Wednesday, September 12, 2007

URLs

How to install an assembly in the Global Assembly Cache in Visual Basic .NET or in Visual Basic 2005

http://support.microsoft.com/kb/315682


Desktops

http://msdn2.microsoft.com/en-us/library/ms682573.aspx


Forum:

http://forums.asp.net/t/1108959.aspx


Tips and tricks

http://office.microsoft.com/en-us/help/HA011423051033.aspx


Outlook
http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032254519&Culture=en-US


Snapshots
http://www.snap.com/about/shotsdownload.php

Concurrency in sql server
http://www.fredshack.com/docs/databases.html

O Priye(Aniyathi pravu)

Movie Name: Aniyathi Pravu (1997)
Singer: Arundathi, Sreekumar M G
Music Director: Ouseppachan
Lyrics: Ramesan Nair
Year: 1997
Director: Fazil


Oo priye..priye ninakkoru gaanam
Oo priye en praananilunarum gaanam
Ariyathe aathamavil chiraku kudanjorazhake
Niramizhiyil himakanamay aliyukayanne viraham (Oo priye

Janmangalaay punyodayangalai kaivanna naalukal
Kannerumaay kaanakkinakkalay nee thannoraashakal
Thira thallumethu kadalay njan pidayunnathethu chirakaay njan
Praanante novil vidaparayum kilimakalay engu poyi nee ( Oo priye

Varnnangalay pushpolsavangalai nee ente vaadiyil
Sangeethamay swapnaadanangalil nee ente jeevanil
Alayunnathethu mukilay njan anayunnathethu thiriyay njan
Ekaatha raavil kanalerium kadhtudaraan engupoyi nee ( Oo priye )

Friday, September 07, 2007

A simple javascript

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language=javascript>
function abc(){
alert("Hello.");

}

if(document.getElementsByTagName) onload = function(){
document.getElementsByTagName("BODY")[0].onclick = abc;

}

</script>
</head>
<body>



<input type=button name=t1 value=Click onclick="javascript:window.open('http://www.msn.com','Mal_Window','addressbar=0;menubar=0;scrollbars=0;height=300;width=400;scrolling=0;');">

</body>
</html>

உன்னாலே உன்னாலே...(Unnaale Unnaale)

Movie Name: Unnaale Unnaale (2006)
Singer: Harini, Karthik, Krish
Music Director: Harris Jeyaraj
Year: 2006
Producer: Oscar Ravi Chandran
Director: Jeeva
Actors: Sada, Tanisha, Vinay


mudhanmudhalaaga mudhammudhalaaga
paravasamaaga paravasamaaga
vA vA vA anbE
thaniththaniyaaga thannandhaniyaaga
ilavasamaaga ilavasamaaga
vA vA vA anbE

unnaalE unnaalE viNNaaLachchendrEnE
unn munnE unn munnE nee kaaNa nindrEnE
oru sottu kadalum nee oru pottu vaanam nee
oru puLLi puyalum nee brahmiththEn
hO oLi veesum iravum nee
uyir kEtkkum amudham nee
imai moodum vizhiyum nee yaasiththEn

mudhanmudhalaaga mudhammudhalaaga
paravasamaaga paravasamaaga
vA vA vA anbE
thaniththaniyaaga thannandhaniyaaga
ilavasamaaga ivan vasamaaga
vA vA vA anbE

mudhanmudhalaaga mudhammudhalaaga
paravasamaaga paravasamaaga
vA vA vA anbE
thaniththaniyaaga thannandhaniyaaga
ilavasamaaga ivan vasamaaga
vA vA vA anbE

oru paarvai neeLaththai oru vaarththai naaNaththai
thaangaamal vizhundhEnE thoongaamal vaazhvEnE
nadhimeedhu sarugaippOl unn paadhai varugindrEn
kari thEtri viduvaayO gadhi mOtchcham tharuvaayO
moththamaai moththamaai naan maarippOnEnE
suththamaai suththamaai thooL thooLaai aanEnE

mudhanmudhalaaga mudhammudhalaaga
paravasamaaga paravasamaaga
vA vA vA anbE
ohO thaniththaniyaaga thannandhaniyaaga
ilavasamaaga ivan vasamaaga
vA vA vA anbE

unnaalE unnaalE viNNaaLachchendrEnE
unn munnE unn munnE nee kaaNa nindrEnE

nee enbadhu mazhayaaga naan enbadhu veyilaaga
mazhayOdu veyyil serum andha vaanilai sugamaagum
sari endru theriyaamal thavarendru puriyaamal
yedhil vandhu sErndhaEn naan yedhirpaarkkavillai naan
enn vasam enn vasam iraNdadukku aagaayam
iraNdilum pOgudhE enn kaadhal kaarmEgam
pa pa pa pa pappa papap paaaaa

unnaalE unnaalE viNNaaLachchendrEnE
unn munnE unn munnE nee kaaNa nindrEnE
oru sottu kadalum nee oru pottu vaanam nee
oru puLLi puyalum nee brahmiththEn
hO oLi veesum iravum nee
uyir kEtkkum amudham nee
imai moodum vizhiyum nee yaasithth En

Thursday, September 06, 2007

Javascript to close all the child windows from a parent window

<html>
<head></head>
<body>
<script>
//The openWindow array will hold the handles of all open child windows
var openWindow = new Array();

//Track open adds the new child window handle to the array.
function trackOpen(winName) {
openWindow[openWindow.length]=winName;
}

//loop over all known child windows and try to close them. No error is
//thrown if a child window(s) was already closed.
function closeWindows() {
var openCount = openWindow.length;
for(r=0;r<openCount;r++) {
openWindow[r].close();
}
}

//Open a new child window and add it to the tracker.
function open1() {
var win1 = open("http://www.yahoo.com");
trackOpen(win1);
}

//Open a different child window and add it to the tracker.
function open2() {
var win2 = open("http://www.google.com");
trackOpen(win2);
}
//Open whatever the user enters and add it to the tracker
function open3() {
var newURL = document.getElementById("url").value;
var win3=open(newURL);
trackOpen(win3);
}

</script>

<input type="button" value="Open 1" onclick="open1()" ID="Button1" NAME="Button1"><br>
<input type="button" value="Open 2" onclick="open2()" ID="Button2" NAME="Button2"><br>
URL: <input type="text" id="url" NAME="url"> <input type="button" value="Open URL" onclick="open3()" ID="Button3" NAME="Button3"><br>
<input type="button" value="Close All" onclick="closeWindows()" ID="Button4" NAME="Button4">

</body>
</html>

Creating table using DIV tags

<div class="main"> <div class="col">column1</div> <div class="col">column2</div> <div class="col">column3</div> <div class="col">column4</div> <div class="clear"></div> <div class="col">column1</div> <div class="col">column2</div> <div class="col">column3</div> <div class="col">column4</div> <div class="clear"></div> <div class="col">column1</div> <div class="col">column2</div> <div class="col">column3</div> <div class="col">column4</div> <div class="clear"></div> <div class="col">column1</div> <div class="col">column2</div> <div class="col">column3</div> <div class="col">column4</div> </div>


<style type="text/css" media="all">.main { width: 500px; }.col { float: left; margin: 2px;}.clear { clear: both;}</style>

Tuesday, September 04, 2007

Tips to Improve ASP.net Application Performance

Disable Session State
Disable Session State if you're not going to use it. By default it's on. You can actually turn this off for specific pages, instead of for every page:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="WebApplication1.WebForm1"
EnableSessionState="false" %>

You can also disable it across the application in the web.config by setting the mode value to Off.

Output Buffering
Take advantage of this great feature. Basically batch all of your work on the server, and then run a Response.Flush method to output the data. This avoids chatty back and forth with the server.

<%response.buffer=true%>
Then use:

<%response.flush=true%>
Avoid Server-Side Validation
Try to avoid server-side validation, use client-side instead. Server-Side will just consume valuable resources on your servers, and cause more chat back and forth.

Repeater Control Good, DataList, DataGrid, and DataView controls Bad
Asp.net is a great platform, unfortunately a lot of the controls that were developed are heavy in html, and create not the greatest scaleable html from a performance standpoint. ASP.net repeater control is awesome! Use it! You might write more code, but you will thank me in the long run!

Take advantage of HttpResponse.IsClientConnected before performing a large operation:

if (Response.IsClientConnected)
{
// If still connected, redirect
// to another page.
Response.Redirect("Page2CS.aspx", false);
}
What is wrong with Response.Redirect? Read on...

Use HTTPServerUtility.Transfer instead of Response.Redirect
Redirect's are also very chatty. They should only be used when you are transferring people to another physical web server. For any transfers within your server, use .transfer! You will save a lot of needless HTTP requests.

Always check Page.IsValid when using Validator Controls
So you've dropped on some validator controls, and you think your good to go because ASP.net does everything for you! Right? Wrong! All that happens if bad data is received is the IsValid flag is set to false. So make sure you check Page.IsValid before processing your forms!

Deploy with Release Build
Make sure you use Release Build mode and not Debug Build when you deploy your site to production. If you think this doesn't matter, think again. By running in debug mode, you are creating PDB's and cranking up the timeout. Deploy Release mode and you will see the speed improvements.

Turn off Tracing
Tracing is awesome, however have you remembered to turn it off? If not, make sure you edit your web.config and turn it off! It will add a lot of overhead to your application that is not needed in a production environment.








Page.IsPostBack is your friend
Make sure you don't execute code needlessly. I don't know how many web developers forget about checking IsPostBack! It seems like such a basic thing to me! Needless processing!

Avoid Exceptions
Avoid throwing exceptions, and handling useless exceptions. Exceptions are probably one of the heaviest resource hogs and causes of slowdowns you will ever see in web applications, as well as windows applications. Write your code so they don't happen! Don't code by exception!

Caching is Possibly the number one tip!
Use Quick Page Caching and the ASP.net Cache API! Lots to learn, its not as simple as you might think. There is a lot of strategy involved here. When do you cache? what do you cache?

Create Per-Request Cache
Use HTTPContect.Items to add single page load to create a per-request cache.

StringBuilder
StringBuilder.Append is faster than String + String. However in order to use StringBuilder, you must
new StringBuilder()
Therefore it is not something you want to use if you don't have large strings. If you are concatenating less than 3 times, then stick with String + String. You can also try String.Concat

Turn Off ViewState
If you are not using form postback, turn off viewsate, by default, controls will turn on viewsate and slow your site.

public ShowOrdersTablePage()
{
this.Init += new EventHandler(Page_Init);
}

private void Page_Init(object sender, System.EventArgs e)
{
this.EnableViewState = false;
}
Use Paging
Take advantage of paging's simplicity in .net. Only show small subsets of data at a time, allowing the page to load faster. Just be careful when you mix in caching. How many times do you hit the page 2, or page 3 button? Hardly ever right! So don't cache all the data in the grid! Think of it this way: How big would the first search result page be for "music" on Google if they cached all the pages from 1 to goggle ;)

Use the AppOffline.htm when updating binaries
I hate the generic asp.net error messages! If I never had to see them again I would be so happy. Make sure your users never see them! Use the AppOffline.htm file!

Use ControlState and not ViewState for Controls
If you followed the last tip, you are probably freaking out at the though of your controls not working. Simply use Control State. Microsoft has an excellent example of using ControlState here, as I will not be able to get into all the detail in this short article.

Use the Finally Method
If you have opened any connections to the database, or files, etc, make sure that you close them at the end! The Finally block is really the best place to do so, as it is the only block of code that will surely execute.

Option Strict and Option Explicit
This is an oldy, and not so much a strictly ASP.net tip, but a .net tip in general. Make sure you turn BOTH on. you should never trust .net or any compiler to perform conversions for you. That's just shady programming, and low quality code anyway. If you have never turned both on, go turn them on right now and try and compile. Fix all your errors.

Monday, September 03, 2007

Agile methodology

http://www.agilemodeling.com/

Simple SQL Server Performance Tips


Always create a data model (ERD).
Consider using an application block or a best practice based design.
Make sure the database is normalized - very important else sql server will not give optimized query plans . For the 1 to many (1:m OR m:1) relation, -> ensure that the child table's primary key has one of its composite keys as the parent table's primary key. All dependent tables must have the parent-primary-key (foreign key) and a surrogate key as its primary key eg. a Person - Address relationship, or a Product - Attribute relationship. For an m:n relation ensure that the two tables have a third table to hold the primary key combinations of both the related tables eg. a many to many relationship.
Make sure database security is controlled through views/stored procedures and finally roles.
All commonly used joins have indexes on the where condition columns. Remember foreign key constraint doesn't mean an index.
Always use Inner Joins if possible then Outer Joins . Use Left Outer joins only when foreign keys are nullable. Try to design around NULL (avoid foreign keys being NULL). Use ANSI_NULL to ensure ANSI NULL compatibility. Remember: SELECT * FROM A1 where b not in (SELECT b from B1) would return null if any b is null.
Keep transactions as short as possible.
Reduce lock time. Try to develop your application so that it grabs locks at the latest possible time, and then releases them at the very earliest time.
Always run/display execution plan from query analyzer when testing out stored procs/ad-hoc sql and ensure clustered index seek or nested loops are used. NO HASH JOINs. I/O or hash joins would mean spikes in CPU usage in the performance monitor(perfmon).
Avoid where conditions with functions since SQL Server doesn't have Function based indices. eg don't use select a,b from X where CONVERT(date) > '10/10/2005', instead move the convert to the RHS constant. This guarantees query exec. plan reuse and also usage of index columns by query plan.
Always run sql profiler and run your client application and ensure that the duration column is not too much, if too much run index tuning wizard which will confirm that no indices are required for the queries.
Always use connection pools for guaranteeing caching of queries results etc. Connection Strings should exactly match for connection pooling, if NT USer use same user while connecting to the database from the client. Remember: NT based connection pooling through delegation doesn't work correctly in ASP.NET, also it isn't as scalable as a SQL user based connection pool. You can always encrypt the connection string in the web.config file
SQL Server .NET data provider is the fastest. The SQL Server .NET provider uses TDS (Tabular Data Stream, which is the native SQL Server data format) to communicate with SQL Server. The SQL Server .NET provider can be used to connect to SQL Server 7.0 and SQL Server 2000 databases, but not SQL Server 6.5 databases. If you need to connect to a SQL Server 6.5 database, the best overall choice is the OLE DB.NET data provider.
2 part name - Always use fully qualify tables/views/stored procs like exec dbo.sp_storeusers or sp_sqlexec rsdb.dbo.sp_storeusers to be compatible with future releases of SQL Server.
SQL Server 2005 supports 64-bit processors and works with the same sql syntax as SQL Server 2000.
Server side cursors are not scalable in SQL Server => avoid .
Cursors are degradable to the next higher cost cursor - when ORDER BY (not covered by index), TOP, GROUP BY, UNION, DISTINCT,.. is used.
Always use DataReaders, then DataTables then DataSets with ADO.NET in that order of performance hit.
Try to use SELECT ... (with NOLOCK) hint. NOLOCK gives dirty data, useful only when readers are much more than writers. If appropriate, reduce lock escalation by using the ROWLOCK or PAGLOCK. Consider using the NOLOCK hint to prevent locking if the data being locked is not modified often.
Always de-allocate and close cursors, close connections.
To check io costs - set statistics io on -- just get stats for touches on the tables (could be index, clustered index or table)
Non-clustered index leads to a bookmark look-up when the clustered index/rowid data is accessed.
Internationalization: Always use UTC time in database and plan for Unicode. Don't assume locale and number of users, design for most scalability. Don't use the NVARCHAR or NCHAR data types unless you need to store 16-bit character (Unicode) data. They take up twice as much space as VARCHAR or CHAR data types, increasing server I/O and wasting unnecessary space in your buffer cache.
ADO.NET calls ad-hoc queries using sp_ExecuteSQL("...") so they will be cached, so no problems with search pages but use the same connection string/pooling. select * from syscacheobjects to check cache.
Avoid SELECT * ==> leads to table scan, also have at least 1 clustered index on a table (unless its very small) Because there is no index on the column to use for the query. It must do a table scan to evaluate each row. A table scan is also done if all columns are requested or the where condition doesn't contain any indices.
use SET => better for assigning single values rather than SELECT eg. SET @a =10
Openxml is costly - it loads the xml parser in sql server so use bulk insert/bulk copy
DBCC - database consistency check (misnomer now!) DBCC FREEPROCACHE (free proc cache) DBCC REINDEX - at night, high cost, table lock, reindex, reapply fill factor which is applied only initially DBCC CHECK - check db consistency DBCC SHOWCONTIG - show defragmentation (extent level, logical scan, scan density) DBCC INDEXDEFRAG - online operation - during day, low cost, page lock, fix logical scan frag.
Maintainance: update statistics every night, reindex every week.
sp_who - show spids currently running and deadlocked ones
Ask for less data over the wire - its better to work like explorer and ask for parent nodes first then child nodes based on user request.
use of DISTINCT is not very scalable => database model error (may not be relational)
Optimizer uses constraints - so use indices,foreign keys etc
Clustered Index Scan or Full Table Scan are because an index is missing, use index tuning wizard with thorough to find the missing index when the application is running and when profiler is used. Index Tuning Wizard can be run on individual queries too from SQL Query Analyser.
SQL Query Optimizer: Select column would affect BOOKMARK LOOKUP, Predicate column (where clause) determines clustered or non-clustered index seek/scan (scan=>between clause), Estimated Resultant rows determines a Clustered Index Scan is to be done or not.
dbcc memorystatus - value of Stolen under Buffer Distribution increase steadily? => either consuming a lot of memory within SQL Server or is not releasing something. When an application acquires a lot of Stolen memory, SQL Server cannot page this to disk like it can for a data or index page. This is memory that must remain in SQL Server’s Buffer Pool and cannot be aged out. If the application is using cursors, memory associated with a cursor requires Stolen Memory while the cursor is open => Perhaps the application is opening up cursors but not closing them before opening a new one.
OR/'in' clauses are not very performant (most of the time they result in a table scan) ==> use unions for large queries.
Always check for SQL Injection problems including comment -- web page injection issues.
A view - "virtual table" - based on views would all be materialized in the tempdb during execution so the query plan used would be based on the sql (if it contains CONVERT, RTRIM functions etc in the where clause, the index wouldn't be used because there are no function based indexes like ORACLE).
Data Types: char == trailing spaces (padded), varchar == no trailing spaces (not-padded).If the text data in a column varies greatly in length, use a VARCHAR data type instead of a CHAR data type. The amount of space saved by using VARCHAR over CHAR on variable length columns can greatly reduce I/O reads, improving overall SQL Server performance. Don't use FLOAT or REAL data types for primary keys, as they add unnecessary overhead that hurts performance. Use one of the integer data types instead.
Avoid SQL Server Application Roles which do not take advantage of connection pooling
Set following for all stored procs========================SET ANSI_NULLS ON -- guarantees ansi null behaviour during concat, IN operationsSET CONCAT_NULL_YIELDS_NULL ON -- any string concat with NULL is NULLSET NOCOUNT ON -- minimize network traffic.
O/RM - Object-relational mapping - Object-relational mapping, or O/RM, is a programming technique that links relational databases to object-oriented language concepts, creating (in effect) a "virtual object database." http://en.wikipedia.org/wiki/Object-relational_mapping
Simple tips from http://www.sql-server-performance.com/david_gugick_interview2.aspBest way to optimize stored procedures:
Limit the use of cursors wherever possible. Use temp tables or table variables instead. Use cursors for small data sets only.
Make sure indexes are available and used by the query optimizer. Check the execution plan for confirmation.
Avoid using local variables in SQL statements in a stored procedure. They are not as optimizable as using parameters.
Use the SET NOCOUNT ON option to avoid sending unnecessary data to the client.
Keep transactions as short as possible to prevent unnecessary locking.
If your application allows, use the WITH (NOLOCK) table hint in SQL SELECT statements to avoid generating read locks. This is particularly helpful with reporting applications.
Format and comment stored procedure code to allow others to properly understand the logic of the procedure.
If you are executing dynamic SQL use SP_EXECUTESQL instead of EXEC. It allows for better optimization and can be used with parameters.
Access tables across all stored procedures in the same logical order to prevent deadlocks from occurring.
Avoid non-optimizable SQL search arguments like Not Equal, Not Like, and, Like ‘%x’.
Use SELECT TOP n [PERCENT] instead of SET ROWCOUNT n to limit the number of rows returned.
Avoid using wildcards such as SELECT * in stored procedures (or any SQL application for that matter).
When executing stored procedures from a client, using ADO for example, avoid requesting a refresh of the parameters for the stored procedure using the Parameters.Refresh() command. This command forces ADO to interrogate the database for the procedure’s parameters and causes excessive traffic and application slowdowns.
Break large queries into smaller, simpler ones. Use table variables or temp tables for temporary storage, if necessary.
Understand your chosen client library (DB-LIB, ODBC, OLE DB, ADO, ADO.Net, etc.) Understand the necessary options to set to make queries execute as quickly as possible.
If your stored procedure generates one or more result sets, fetch those results immediately from the client to prevent prolonged locking. This is especially important if your client library is set to use server-side cursors.
Do not issue an ORDER BY clause in a SELECT statement if the order of rows returned is not important.
Put all DDL statements (like CREATE TABLE) before any DML statements (like INSERT). This helps prevent unwanted stored procedure recompiles.
Only use query hints if necessary. Query hints may help performance, but can prevent SQL Server from choosing the best execution plan. A query hint that works today may not work as well tomorrow if the underlying data changes in size or statistical distribution. Try not to out think SQL Server’s query processor.
Consider using the SQL Server query governor cost limit option to prevent potentially long running queries from ever executing. Best index tuning:
Examine queries closely and keep track of column joins and columns that appear in WHERE clauses. It’s easiest to do this at query creation time.
Look for queries that return result sets based on ranges of one or more columns and consider those columns for the clustered index.
Avoid creating clustered primary keys if the PK is on an IDENTITY or incrementing DATETIME column. This can create hot-spots at the end of a table and cause slow inserts if the table is “write” heavy.
Avoid excessive indexes on columns whose statistical distribution indicates poor selectivity, i.e. values found in a large number of rows, like gender (SQL Server will normally do a table scan in this case).
Avoid excessive indexes on tables that have a high proportion of writes vs. reads.
Run the Index Tuning Wizard on a Coefficient trace file or Profiler trace file to see if you missed any existing indexes.
Do not totally rely on the Index Tuning Wizard. Rely on your understanding of the queries executed and the database.
If possible, make sure each table has a clustered index, which may be declared in the primary key constraint (if you are using a data modeling tool, check the tool’s documentation on how to create a clustered PK).
Indexes take up extra drive space, slow down INSERTs and UPDATEs slightly, and require longer backup/replication times, but since most tables have a much higher proportion of reads to writes, you can usually increase overall performance creating the necessary indexes, as opposed to not creating them.
Remember that the order of columns in a multi-column index is important. A query must make use of the columns as they are listed in the index to get the most performance increase. While you don’t need to use all columns, you cannot skip a column in the index and still receive index performance enhancement on that column.
Avoid creating unique indexes on columns that allow NULL values.
On tables whose writes far outweigh reads, consider changing the FILLFACTOR during index creation to a value that allows for adequate free space on the index pages to allow for optimal table inserts.
Make sure SQL Server is configured to auto update and auto create statistics. If these options cause undue strain on the server during business hours and you turn them off, make sure you manually update statistics, as needed.
Consider rebuilding indexes on a periodic basis, by recreating them (consider using the DROP_EXISTING clause), using DBCC INDEXDEFRAG (SQL 2000), or DBCC DBREINDEX. These commands defragment an index and return the fill factor space to the leaf level of each index page. Consider a mix/match of each of these commands for your environment.
Do not create indexes that contain the same column. For example, instead of creating two indexes on LastName, FirstName and LastName, eliminate the second index on LastName.
Avoid creating indexes on descriptive CHAR, NCHAR, VARCHAR, and NVARCHAR columns that are not accessed often. These indexes can be quite large. If you need an index on a descriptive column, consider using an indexed view on a smaller, computed portion of the column. For example, create a view:CREATE VIEW view_nameWITH SCHEMABINDINGASSELECT ID, SUBSTRING(col, 1, 10) as colFROM tableThen create an index on the reduced-sized column col:CREATE INDEX name on view_name (col). This index can still be used by SQL Server when querying the table directly (although you would be limited in this example to searching for the first 10 characters only). Note: Indexed views are SQL Server 2000 only.
Use surrogate keys, like IDENTITY columns, for as many primary keys as possible. INT and BIGINT IDENTITY columns are smaller than corresponding alpha-numeric keys, have smaller corresponding indexes, and allow faster querying and joining.
If a column requires consistent sorting (ascending or descending order) in a query, for example:SELECT LastName, FirstNameFROM CustomersWHERE LastName LIKE N%ORDER BY LastName DESCConsider creating the index on that column in the same order, for example:CREATE CLUSTERED INDEX lastname_ndxON customers(LastName, FirstName) DESC. This prevents SQL Server from performing an additional sort on the data.
Create covering indexes wherever possible. A covering index covers all columns selected and referenced in a query. This eliminates the need to go to the data pages, since all the information is available in the index itself. Benefits of using stored procedures
Stored procedures facilitate code reuse. You can execute the same stored procedure from multiple applications without having to rewrite anything.
Stored procedures encapsulate logic to get the desired result. You can change stored procedure code without affecting clients (assuming you keep the parameters the same and don’t remove any result sets columns).
Stored procedures provide better security to your data. If you use stored procedures exclusively, you can remove direct Select, Insert, Update, and Delete rights from the tables and force developers to use stored procedures as the method for data access.
Stored procedures are a part of the database and go where the database goes (backup, replication, etc.).
Stored procedures improve performance. SQL Server combines multiple statements in a procedure into a unified execution plan.
Stored procedures reduce network traffic by preventing users from having to send large queries across the network.
SQL Server retains execution plans for stored procedures in the procedure cache. Execution plans are reused by SQL Server when possible, increasing performance. Note SQL 7.0/2000: this feature is available to all SQL statements, even those outside stored procedures, if you use fully qualified object names.
Top 10 Must Have Features in O/R Mapping Tools at http://www.alachisoft.com/articles/top_ten.html - 1. Flexible object mapping -Tables & views mapping, Multi-table mapping, Naming convention, Attribute mapping, Auto generated columns, Read-only columns, Required columns, Validation, Formula Fields, Data type mapping, 2. Use of existing Domain objects, 3. Transactional operations - COM+/MTS,Stand-alone, 4. Relationships and life cycle management - 1 to 1, many to 1, 1 to many, many to many, 5. Object inheritance - 1 table per object or 1 table for all objects - handling insert, update, delete and load data, 6. Static and dynamic queries, 7. Stored procedure calls,8. Object caching, 9. Customization of generated code and re-engineering support, 10. Code Template Customization
Perform an audit of the SQL Code http://www.sql-server-performance.com/sql_server_performance_audit8.aspTransact-SQL Checklist
Does the Transact-SQL code return more data than needed?
Are cursors being used when they don't need to be?
Are UNION and UNION SELECT properly used?
Is SELECT DISTINCT being used properly?
Does the WHERE clause make use of indexes in search criteria?
Are temp tables being used when they don't need to be?
Are hints being properly used in queries?
Are views unnecessarily being used?
Are stored procedures being used whenever possible?
Inside stored procedures, is SET NOCOUNT ON being used?
Do any of your stored procedures start with sp_?
Are all stored procedures owned by DBO, and referred to in the form of databaseowner.objectname?
Are you using constraints or triggers for referential integrity?
Are transactions being kept as short as possible? Application Checklist
Is the application using stored procedures, strings of Transact-SQL code, or using an object model, like ADO, to communicate with SQL Server?
What method is the application using to communicate with SQL Server: DB-LIB, DAO, RDO, ADO, .NET?
Is the application using ODBC or OLE DB to communication with SQL Server?
Is the application taking advantage of connection pooling?
Is the application properly opening, reusing, and closing connections?
Is the Transact-SQL code being sent to SQL Server optimized for SQL Server, or is it generic SQL?
Does the application return more data from SQL Server than it needs?
Does the application keep transactions open when the user is modifying data?

Thanks to the authors at http://www.sql-server-performance.com/ and the other sites listed above.

Wednesday, August 22, 2007

To disable right click option on IE(Internet Explorer)

To disable right click option on IE(Internet Explorer)
use <BODY oncontextmenu="return false" >

Wednesday, August 01, 2007

Source codes

Source codes

Tips and tricks

Tips and tricks...

Error:
Error while trying to run project :Unable to start debugging
The debugger is not properly installed.Run setup to install or repair the debugger.
Solution:
1. http://blogs.msdn.com/greggm/archive/2004/04/16/114828.aspx
2. http://support.microsoft.com/kb/303067

Case 1:
Please go to the MS Visual studio command prompt and type as follows:

c:\your vs folder> aspnet_regiis -i

Case 2:
Check the properties in your inetmgr and change accordingly


SQL Optimization Tips:
http://dotnetguts.blogspot.com/2007/08/sql-optimization-tips.html

A truth....

Monday, July 30, 2007

10 telephone blunders that could hurt your image



10 telephone blunders


Courtesy:

http://blogs.techrepublic.com.com/10things/?p=196&tag=nl.e138

Worthwhile?

Friday, July 27, 2007

Narumugayae.. Lyrics

Movie Name: Iruvar (1997)
Singer: Bonnie Chakraborthy, Unni Krishnan
Music Director: Rahman AR
Year: 1997
Actors: Aishwarya Rai, Mohanlal, Prakash Raj


narumugaiyae narumugaiyae neeyoru naazhigai nillaay
sengani ooriya vaay thirandhu neeyoru thirumozhi sollaay
attraith thingal annilavil netriththarala neervadiya kotrappoigai aadiyaval neeyaa (2)
thirumaganae thirumaganae nee oru naazhigaip paaraay
vennirap puraviyil vandhavanae vaelvizhi mozhigal kaelaay
attraith thingal annilavil kotrappoigai aadugaiyil otrappaarvai paarththavanum neeyaa(2)

mangai maanvizhi ambugal en maarthulaiththadhenna
paandinaadanaik kandu enmanam pasalai kondadhenna
nilaavilae paarththa vannam kanaavilae thoanrum innum (2)
ilaiththaen thudiththaen porukkavillai idaiyinil maegalai irukkavillai
narumugaiyae narumugaiyae neeyoru naazhigai nillaay
attraith thingal annilavil kotrappoigai aadugaiyil otrappaarvai paarththavanum neeyaa
attraith thingal annilavil netriththarala neervadiya kotrappoigai aadiyaval neeyaa (2)

yaayum yaayum yaaraagiyaroanenru naerndhadhenna
yaanum neeyum evvazhiyaridhum uravu saerndhadhenna
orae oru theendal seydhaay uyirkkodi pooththadhenna (2)
sembulam saerndha neerththuli poal ambudai nenjam kalandhadhenna
thirumaganae thirumaganae nee oru naazhigaip paaraay
attraith thingal annilavil kotrappoigai aadugaiyil otrappaarvai paarththavanum neeyaa
attraith thingal annilavil netriththarala neervadiya kotrappoigai aadiyaval neeyaa (2)

Numeric only textbox

<script language="javascript" type="text/javascript"><!--function intOnly(i) { if(i.value.length>0) { i.value = i.value.replace(/[^\d]+/g, ''); }}//--></script>Integer Only Textbox:<br><input type="text" onChange="intOnly(this);" onKeyUp="intOnly(this);" onKeyPress="intOnly(this);">

A javascript to search/match any word from the dropdown

<html>
<head>
</head>
<body>
<br>
<center>
<center>
<br>
 <br>
<br>
<table cellpadding="0" cellspacing="0" border="0" ID="Table1">
<tr>
<td width="200" align="center">
<select class="TxtArea" id="MySelect1" size="6" style="WIDTH:100px" NAME="MySelect1">
<option>Select</option>
<option>Coca Cola</option>
<option>Fanta</option>
<option>Pepsi Cola</option>
<option>X Cola</option>
</select>
<br>
Filter by <input class="TxtArea" type="text" size="10" autocomplete="off" onkeyup=" f32_FillSel(this,'MySelect1');"
ID="Text1" NAME="Text1">
<br>
</td>
<td width="200" align="center">
<select class="TxtArea" id="MySelect2" size="2" style="WIDTH:100px" NAME="MySelect2">
<option>Select</option>
<option>Tom</option>
<option>Dick</option>
<option>Harry</option>
<option>Bert</option>

<option>Saravanan</option>
<option>Amitabh</option>
</select>
<br>
Filter by <input class="TxtArea" type="text" size="10" autocomplete="off" onkeyup=" f32_FillSel(this,'MySelect2');"
ID="Text2" NAME="Text2">
</td>
</tr>
</table>
<br>
<script language="JavaScript" type="text/javascript">
<!--

var f32_TB,f32_ID;
function f32_InitSelectList(f32_id,axcary){
f32_id=document.getElementById(f32_id);
for (f32_1=0;f32_1<f32_ary.length;f32_1++){
f32_id.options[f32_id.options.length]=new Option(f32_ary[f32_1][0],f32_ary[f32_1][1],true,true);
}
}
function f32_FillSel(f32_tb,f32_id){
f32_TB=f32_tb; f32_ID=f32_id;
f32_tv=f32_tb.value.toLowerCase();
f32_id=document.getElementById(f32_id);
f32_tb.onkeypress=function(evt){ f32_BackSpace(evt?evt.keyCode:event.keyCode); }
f32_tb.onblur=function(){ this.onkeypress=null; }
if (!f32_id.ary){
f32_id.sary=new Array();
f32_id.ary=new Array();
for (f32_0=0;f32_0<f32_id.options.length;f32_0++){
f32_id.ary[f32_0]=[f32_id.options[f32_0].text,f32_id.options[f32_0].value];
}
}
f32_ary=new Array();
for (f32_0=0;f32_0<f32_id.ary.length;f32_0++){
if (f32_id.ary[f32_0][0].toLowerCase().match( f32_tv)&&f32_tv!=''&&f32_tv!=' '){
f32_ary[f32_ary.length]=f32_id.ary[f32_0];
}
}
if (f32_ary.length<1){ f32_ary=f32_id.ary; }
if (f32_id.sary!=f32_ary){
f32_id.options.length=0;
for (f32_1=0;f32_1<f32_ary.length;f32_1++){
f32_id.options[f32_id.options.length]=new Option(f32_ary[f32_1][0],f32_ary[f32_1][1],true,true);
}
}
f32_id.selectedIndex=-1;
f32_id.sary=f32_ary;
f32_tb.focus();
}
function f32_BackSpace(e){
if (e==8){ f32_FillSel(f32_TB,f32_ID); }
}
//-->
</script>

</center>
</center>
</body>
</html>

Queries to select max(sal) from a table in SQL server

select distinct(sal) from emp e1 where ( select count(distinct(sal)) from emp e2 where e2.sal >= e1.sal ) = 2
where 2 is the second max salary .

4th Max

select max(sal) from EMP A where 4=( select count(sal) From EMP B where B.sal>=A.sal)

5th Max

select max(sal) from EMP A where 5=( select count(sal) From EMP B where B.sal>=A.sal)

Nth Max

select max(sal) from EMP A where N=( select count(sal) From EMP B where B.sal>=A.sal)

A simple javascript function to convert to uppercase

<html>
<head> <script type="text/javascript"> function upperCase(x) { var y=document.getElementById(x).value document.getElementById(x).value=y.toUpperCase() } </script> </head>
<body>
Enter your name: <input type="text" id="fname" onkeyup="upperCase(this.id)">
</body> </html>

A simple datagrid with add, edit, sort, delete features( which uses a stored procedure)

test.aspx

<%@ Page language="c#" Codebehind="test.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.test" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>test</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:datagrid id="dg" runat="server" width="80%" CellSpacing="1" GridLines="None" CellPadding="3"
BackColor="White" ForeColor="Black" OnPageIndexChanged="dg_Page" PageSize="10" AllowPaging="True"
DataKeyField="eid" Font-Size="X-Small" AutoGenerateColumns="false" AllowSorting="True" Font-Names="Verdana"
OnDeleteCommand="dg_Delete" OnItemCreated="dg_ItemCreated" OnEditCommand="dg_Edit" OnCancelCommand="dg_Cancel"
OnUpdateCommand="dg_Update" OnItemCommand="dg_Item" OnSortCommand="dg_Sort">
<FooterStyle backcolor="#C6C3C6"></FooterStyle>
<HeaderStyle font-bold="True" forecolor="White" backcolor="#4A3C8C"></HeaderStyle>
<PagerStyle horizontalalign="Right" backcolor="#C6C3C6" mode="NumericPages"></PagerStyle>
<AlternatingItemStyle backcolor="LightSteelBlue"></AlternatingItemStyle>
<ItemStyle backcolor="#DEDFDE"></ItemStyle>
<Columns>
<asp:TemplateColumn headertext="Email Status" SortExpression="EmailStatus" FooterText="Email Status">
<ItemTemplate>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn headertext="Email Type" SortExpression="EmailType" FooterText="Email Type">
<ItemTemplate>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn headertext="Email Content" SortExpression="Emailcontent" FooterText="Email Content">
<ItemTemplate>
</ItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete" DataTextField="eid" DataTextFormatString="Delete"></asp:ButtonColumn>
</Columns>
</asp:datagrid><asp:button id="btnAdd" onclick="dg_Add" runat="server" Font-Size="smaller" Text="Add New"></asp:button>
</form>
<asp:label id="Label1" runat="server" Visible="False"></asp:label><asp:label id="Label2" runat="server" Visible="False"></asp:label><asp:label id="Label3" runat="server" Visible="True"></asp:label><br>
<asp:label id="lblMessage" runat="server" ForeColor="Red" Font-Bold="True">Label</asp:label>
</body>
</HTML>

--------------------------------------------------------------------------------

test.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace WebApplication1
{
///
/// Summary description for test.
///

public class test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dg;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected string strEmailContent;
protected string strEmailStatus;
protected string message="";
protected string strSqlConn ="Server=servername;Database=itrfsdev;UID=rfs;PWD=rfs;";
SqlConnection sqlConn = new SqlConnection("Server=servername;Database=itrfsdev;UID=rfs;PWD=rfs;");
protected System.Web.UI.WebControls.Label lblMessage;
bool bEditing =false;
private DataSet ds;
private string action;
protected System.Web.UI.WebControls.Button btnAdd;
private int clickedIndex;
public void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
this.Label1.Text="ASC";
BindGrid();
}
}


private void BindGrid()
{

SqlDataAdapter sda= new SqlDataAdapter("select rfses.eid as eid,rfses.emailstatus as emailstatus,rfses.emailtype as emailtype ,rfset.emailcontent as emailcontent from rfs_emailtemplates rfset " +
" inner join rfs_emailstatus rfses on rfset.eid= rfses.eid ",sqlConn);
try
{
ds = new DataSet();
sda.Fill(ds);
sda.Fill(ds,"MessageNotes");
DataView dv= ds.Tables["MessageNotes"].DefaultView;
if(Label2.Text!="")
{
dv.Sort = this.Label2.Text+ " " + Label1.Text;
}
dg.DataSource= dv;
dg.DataBind();
Session.Add("MessageNotes",ds);
this.lblMessage.Visible=false;
}
catch(Exception e)
{
try
{
this.dg.CurrentPageIndex=0;
this.dg.DataBind();
}
catch
{
this.lblMessage.Text="No data for selection";
this.lblMessage.Visible=true;
}
}
finally
{
sqlConn.Close();
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///


private void InitializeComponent()
{
this.dg.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dg_ItemCommand);
this.dg.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dg_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
protected void dg_Page(object sender, DataGridPageChangedEventArgs dpe)
{
if(!bEditing)
{
dg.CurrentPageIndex= dpe.NewPageIndex;
BindGrid();
}
}

protected void dg_Sort(object sender, DataGridSortCommandEventArgs dse)
{
if(!bEditing)
{
if(Label2.Text == dse.SortExpression)
{
if( Label1.Text == "ASC" )
{
this.Label1.Text = "DESC";
}
else
{
this.Label1.Text = "ASC";
}
}
Label2.Text = dse.SortExpression;
BindGrid();
}
}

protected void dg_Edit(object sender, DataGridCommandEventArgs e)
{
if(e.CommandName == "Edit")
{
dg.EditItemIndex = e.Item.ItemIndex;
BindGrid();
SingleColumn(true);
}
}

protected void dg_Cancel(object sender, DataGridCommandEventArgs dce)
{
dg.EditItemIndex = - 1;
BindGrid();
SingleColumn(true);
}

protected void dg_Update(object sender, DataGridCommandEventArgs due)
{
string emailContent="";
dg.EditItemIndex = - 1;
int ctrindex = 3;
int index =0;
sqlConn.Open();
string sTID = dg.DataKeys[(int)due.Item.ItemIndex].ToString();
if(action=="Update" && ViewState["index"]!=null)
{
index = int.Parse(ViewState["index"].ToString())+3;
}
else if(action=="Add")
{
index = ds.Tables[0].Rows.Count;
}
string ClientIDBase = dg.ClientID + ":_ctl" +index+ ":_ctl" +ctrindex;
if( Request.Params[ClientIDBase]!=null)
{
emailContent = Request.Params[ClientIDBase].Trim();
string strcmd= "update rfs_emailTemplates set emailcontent='"+emailContent+"' where eid="+sTID;
SqlCommand sdcmd= new SqlCommand(strcmd,sqlConn);
try
{
sdcmd.ExecuteNonQuery();
}
catch(SqlException se)
{
Label3.Text = se.ToString();
}
finally
{
sqlConn.Close();
}
BindGrid();
SingleColumn(true);
message="Email content updated successfully";
DisplayMessage(message);
}
}

public DataSet BindEmailStatus()
{
string sql= " select distinct EmailStatus,eid from rfs_emailstatus order by eid";
DataSet ds = getDataSet(sql);
return ds;
}

public DataSet BindEmailType()
{
string sql= " select distinct EmailType from rfs_emailstatus";
DataSet ds = getDataSet(sql);
return ds;
}

public DataSet getDataSet(string sql)
{
DataSet dataSet = new DataSet();
SqlDataAdapter DetailsAdapter = new SqlDataAdapter();
SqlCommand myCommand =new SqlCommand();
myCommand.CommandText = sql;
myCommand.CommandType = CommandType.Text;
DetailsAdapter.SelectCommand = myCommand;

try
{
sqlConn.Open();
myCommand.Connection = sqlConn;
DetailsAdapter.Fill(dataSet,"myTable");
}
catch(Exception e)
{
closeOleDbConnection(sqlConn);
throw;
}

closeOleDbConnection(sqlConn);
return dataSet;
}

private void closeOleDbConnection(SqlConnection sqlConn)
{
if( sqlConn != null)
sqlConn.Close();
}

protected void dg_Delete(object sender, DataGridCommandEventArgs dde)
{
if(!bEditing)
{
string sTID = dg.DataKeys[(int)dde.Item.ItemIndex].ToString();
sqlConn.Open();
SqlCommand sdcmd= new SqlCommand("delete from rfs_emailTemplates where eid="+sTID,sqlConn);
sdcmd.ExecuteNonQuery();
sqlConn.Close();
dg.CurrentPageIndex=0;
dg.EditItemIndex=-1;
BindGrid();
message= " Record deleted successfully";
DisplayMessage(message);
}
}

protected void dg_Add(object sender, EventArgs e)
{
CheckEditing("");
int index =0;
action = "Add";
if(Session["MessageNotes"] != null)
{
ds = Session["MessageNotes"] as DataSet;
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
dg.DataSource = ds.Tables[0].DefaultView;
dg.DataBind();
}
if(!bEditing)
{
if(ViewState["index"]!=null)
{
index = int.Parse(ViewState["index"].ToString())+3;
}
}
}

public void InsertEmailContent()
{
int index=0;
string emailContent="";
int eID =0;
int ctrindex=2;
if(action=="Update" && ViewState["index"]!=null)
{
index = int.Parse(ViewState["index"].ToString())+3;
}
else if(action=="Save")
{
if(Session["MessageNotes"] != null)
{
ds = Session["MessageNotes"] as DataSet;
index = ds.Tables[0].Rows.Count+2;
}
}
string emailStatusClientIDBase = dg.ClientID + ":_ctl" +index+ ":_ctl" +ctrindex;
string emailContentClientIDBase = dg.ClientID + ":_ctl" +index+ ":_ctl" +(ctrindex+2);
sqlConn.Open();
try
{
if( Request.Params[emailStatusClientIDBase]!=null)
{
eID = int.Parse (Request.Params[emailStatusClientIDBase].Trim());
}
if( Request.Params[emailContentClientIDBase]!=null)
{
emailContent = Request.Params[emailContentClientIDBase].Trim();
}

SqlCommand sicmd= new SqlCommand("RFS_InsertEmailContent",sqlConn);
sicmd.CommandType= CommandType.StoredProcedure;
sicmd.Parameters.Add( new SqlParameter( "@eID",eID));
sicmd.Parameters["@eID"].Direction = ParameterDirection.Input;
sicmd.Parameters.Add( new SqlParameter("@emailContent",emailContent));
sicmd.Parameters["@emailContent"].Direction = ParameterDirection.Input;
sicmd.Parameters.Add("@displaymessage", SqlDbType.VarChar,3000);
sicmd.Parameters["@displaymessage"].Direction = ParameterDirection.Output;
sicmd.ExecuteNonQuery();
message = (string)sicmd.Parameters["@displaymessage"].Value;
sqlConn.Close();
dg.CurrentPageIndex = dg.PageCount - 1;
SingleInsertColumn(true);
BindGrid();
DisplayMessage(message);
}
catch (System.Data.SqlClient.SqlException ex)
{
Trace.Write(ex.Message);
}
catch (Exception ex) // catch other errors
{
Trace.Write(ex.Message);
}
}
private void DisplayMessage(string message)
{
this.lblMessage.Visible=true;
this.lblMessage.Text =message;
}

protected void dg_ItemCreated(object sender, DataGridItemEventArgs die)
{
if(die.Item.ItemType == ListItemType.Item || die.Item.ItemType == ListItemType.AlternatingItem)
{
WebControl deletebutton = (WebControl) die.Item.Cells[4].Controls[0];
deletebutton.Attributes.Add("onclick","return confirm('Are you sure you want to delete this record?');");
}
}
protected void dg_Item(object sender, DataGridCommandEventArgs di)
{
CheckEditing(di.CommandName);
action = "Save";
if(di.CommandName == "Save")
{
InsertEmailContent();
}
}

private void SingleInsertColumn(bool b)
{
int i;
for(i=2;i<=dg.Columns.Count - 1; i++)
{
dg.Columns[i].Visible = b;
}
Label3.Text="";
}
private void SingleColumn(bool b)
{
int i;
for(i=2;i<=dg.Columns.Count - 1; i++)
{
dg.Columns[i].Visible = b;
}
Label3.Text="";
}


private void CheckEditing(string commandName)
{
if(dg.EditItemIndex != -1)
{
if(commandName!="Cancel" && commandName!="Update")
{
Label3.Text = "Please click update to save your changes, or cancel to discard your changes, before selecting another item.";
bEditing = true;
}
}
}
private void dg_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if(e.Item.DataItem == null)
{
return;
}
DataRowView drV = e.Item.DataItem as DataRowView;
if(action=="Add" && (e.Item.ItemIndex == ds.Tables[0].Rows.Count-1))
{
DropDownList ddlEmailStatus = new DropDownList();
ddlEmailStatus.DataSource=BindEmailStatus();
ddlEmailStatus.DataTextField="EmailStatus";
ddlEmailStatus.DataValueField="eid";
ddlEmailStatus.DataBind();
e.Item.Cells[0].Controls.Add(ddlEmailStatus);
DropDownList ddlEmailType = new DropDownList();
ddlEmailType.DataSource=BindEmailType();
ddlEmailType.DataTextField="EmailType";
ddlEmailType.DataValueField="EmailType";
ddlEmailType.DataBind();
e.Item.Cells[1].Controls.Add(ddlEmailType);
TextBox tbEmailContent=new TextBox();
tbEmailContent.Text="";
tbEmailContent.TextMode = TextBoxMode.MultiLine;
tbEmailContent.Height=150;
tbEmailContent.Width=400;
e.Item.Cells[2].Controls.Add(tbEmailContent);
Button btnAddNew =e.Item.Cells[3].Controls[0] as Button;
btnAddNew.Text = "Save";
btnAddNew.CommandName = "Save";
e.Item.Cells[4].Controls[0].Visible=false;
}
else if(action=="Edit")
{
e.Item.Cells[0].Text=drV["EmailStatus"].ToString() ;
e.Item.Cells[1].Text=drV["EmailType"].ToString() ;
if(e.Item.ItemIndex == clickedIndex)
{
ViewState["index"] = e.Item.ItemIndex;
TextBox tb=new TextBox();
tb.Text = drV["EmailContent"].ToString() ;
e.Item.Cells[2].Controls.Add(tb);
tb.TextMode = TextBoxMode.MultiLine;
tb.Height=150;
tb.Width=400;
e.Item.Cells[4].Controls[0].Visible=false;
}
else
{
e.Item.Cells[2].Text=drV["EmailContent"].ToString() ;
e.Item.Cells[4].Controls[0].Visible=true;
}
}
else
{
e.Item.Cells[0].Text=drV["EmailStatus"].ToString() ;
e.Item.Cells[1].Text=drV["EmailType"].ToString() ;
e.Item.Cells[2].Text=drV["EmailContent"].ToString() ;
}
}
private void dg_ItemCommand(object sender,DataGridCommandEventArgs e)
{
action = e.CommandName;
clickedIndex = e.Item.ItemIndex;
}
}
}


Stored procedure

create procedure RFS_InsertEmailContent @eid int, @emailcontent varchar(3000) ='', @displaymessage varchar(2000) out as
declare @msg varchar(1000)
SET NOCOUNT ON
IF NOT EXISTS(select eid from rfs_emailstatus where eid=@eid)
begin
set @displaymessage= 'This status is not available'

return
end
IF EXISTS(select eid from rfs_emailtemplates where eid=@eid)
begin
set @displaymessage= 'This status is already available'

end
else
begin
begin tran

INSERT INTO rfs_emailtemplates values (@eid,@emailcontent)
set @displaymessage= 'Email content added successfully'

if (@@ERROR <>0) GOTO ERRHANDLER
commit tran
return(1)
ERRHANDLER:
ROLLBACK TRAN
return(0)
end
GO

Table Structure
create table RFS_EmailStatus(eid int primary key not null identity,
EmailStatus varchar(200) unique, EmailType varchar(3))
GO
create table RFS_EmailTemplates(etid int primary key not null identity, eid int ,EmailContent varchar(3000))
GO
ALTER TABLE rfs_emailtemplates ADD UNIQUE(eid)
GO
ALTER TABLE rfs_emailstatus ADD UNIQUE(eid)
GO
alter table RFS_EmailTemplates add constraint fk_RFS_EmailTemplates_RFS_EmailStatus foreign key(eid)
references RFS_EmailStatus(eid) on update cascade
GO
insert into RFS_EmailStatus
select 'RFS_approved email','RFS'
union all
select 'RFS_closedemail email','RFS'
GO
insert into rfs_emailtemplates
select 1,'RFS approved email content'
union all
select 2,'RFS closed email content'
GO

Enjoy :)

Monday, July 23, 2007

Function to Reverse the String without any loop

//// Function to Reverse the String without any loop
String Reverse(String strParam)
{
if (strParam.Length == 1)
return strParam;
else
return Reverse(strParam.Substring(1)) + strParam.Substring(0, 1) ;
}

தமிழ்மன்றம்



தமிழர்களுக்கான ஒரு மன்றம்.

தமிழ்மன்றம்

Function to find palindrome or not without Reversing the string

////Function to find palindrome or not without Reversing the string

private bool IsPalindrome(string str)
{
if((str==null) || (str.Length==0))
return false;
bool r=true;
for (int i = 0,n=str.Length-1; i < n && r; i++, n--)
r = str[i] == str[n];
return r;
}

BDOTNET


Bangalore .NET (BDOTNET) user's group is about helping you understand the .NET framework, show how it will make you more productive and transition your development processes to the same, amongst other things.

Detailed technical insights are presented by Microsoft RDs, .NET MVPs in the technical sessions conducted periodically.

So, if you are a novice, or an intermediate or an advanced developer, transitioning or already working on .NET, BDOTNET is the place to be to quench your .NET thirst!

Tuesday, April 03, 2007

Heart attack and drinking warm water

Please read this and forward it to those you care.




Heart Attacks and drinking warm water....



This is a very good article. Not only about the warm water after your meal, but
about heart attacks. This makes sense.. the Chinese and Japanese drink hot tea
with their meals...not cold water...maybe it is time we adopt their drinking
habit while eating!!!




Nothing to lose, everything to gain...



For those who like to drink cold water, this article is applicable to you. It
is nice to have a cup of cold drink after a meal. However, the cold water will
solidify the oily stuff that you have just consumed. It will slow down the
digestion. Once this "sludge" reacts with the acid, it will break down and be
absorbed by the intestine faster than the solid food. It will line the
intestine. Very soon, this will turn into fats and lead to cancer. It is best
to drink hot soup or warm water after a meal.




A serious note about heart attacks: You should know that not every heart attack
symptom is going to be the left arm hurting. Be aware of intense pain in the
jaw line.



You may never have the first chest pain during the course of a heart attack.
Nausea and intense sweating are also common symptoms. 60% of people who have a
heart attack while they are asleep do not wake up. Pain in the jaw can wake you
from a sound sleep. Let's be careful and be aware. The more we know, the better
chance we could survive...  :)

Customer care contact numbers



  • ICICI Bank Customer Care Number



    • Bangalore - 4113 1877

    • Karnataka - 98455 78000

    • For other cities, click here. Phone Banking workflow click here.



  • Citibank Customer Care Number

    • All Citibank customers - Bangalore - 2227 2484. For other cities, click here

    • Citibank Suvidha account holders - Bangalore - 2227 2265. For other cities, click here

    • CitiBusiness Customers - Bangalore - 2229 4653. For other cities, click here

    • Citibank Credit Card - Bangalore - 2227 2484. For other cities, click here

    • Priority service to CitiGold Customers, Diners Club Members & Citibank Gold Card members - Bangalore - 2229- 4653. For other cities, click here



  • HSBC Customer Care Number

    • Banking related - Bangalore - 2558 9595

    • Credit card related - Bangalore - 2558 9696

    • For other cities, click here



  • HDFC Customer Care Number

    • Debit card related - 9945863333

    • Banking related - Bangalore - 5500 3333. For other cities, click here

    • Credit card related - Bangalore - 6622 4332. For other cities, click here



  • ABN AMRO Customer Care number

    • Bangalore - 4124 5555



  • SBI Credit Card Customer Care Number

    • Karnataka - Bangalore - 98441 05454 (people are reporting that this number does not work. If you know a number that works, please let me know!)

    • All India Toll Free - 1600 180 1290 (works only on BSNL and MTNL Line)

    • Try : 1800 180 1290 too. May work!!!

    • Other lines : 39 02 02 02



  • UTI Bank Customer Care Numbers

    • Bangalore (M G Road) - 2537 0615

    • Bangalore - 2531 7830

    • Mumbai - 022 5598 7700

    • For other cities, click here



  • IDBI Bank Customer Care Number (Phone Banking)

    • Karnataka - Bangalore - 080 22297000

    • Mumbai - 022 66937000

    • Delhi - 011 23627000

    • Chennai - 044 28295550

    • For other cities, click here



  • Manhattan Credit Card Customer Care Number

    • Bangalore - 3030 1969. (this number seems to work in Mumbai too! Give it a try in your local city!)



  • Standard Chartered Credit Card Customer Care Number

    • Bangalore - 2558 8888 (updated). For other cities, click here



  • Airtel Customer Care

    • Dail 121 from your airtel mobile

    • Karnataka - 98450 98450 - For prepaid if you are calling from landline

    • Karnataka - 98450 12345 - For postpaid if you are calling from landline



  • Hutch Customer Care

    • Karnataka - Dial 111 from your Hutch phone or dial 98860 98860



  • BSNL Mobile Customer Care (Cellone & Excel)

    • Karnataka - Dial 94480 24365

    • For other cities, click here.