Showing posts with label dotnet. Show all posts
Showing posts with label dotnet. Show all posts

22 August 2011

how to know the current system name and ip address in asp.net

Response.Write(Request.ServerVariables["REMOTE_ADDR"].ToString()+"<br/>");
Response.Write(
HttpContext.Current.Server.MachineName);

21 July 2011

Some Coding Standards in .net

1.    Use Meaningful, descriptive words to name variables. Do not use abbreviations.
    Good:
    string address
    int salary
     Not Good:
           string name
       string addr
      int sal

2. Do not use single character variable names like i, n, s etc. Use names like index, temp
     variable 'i' is used for for iterations in loops
        Ex:  for ( int i = 0; i < count; i++ ){....}

3.  Do not use underscores (_) for local variable names. But member variables must be prefixed with underscore (_)

4.  Prefix boolean variables, properties and methods with “is” or similar prefixes.
      Ex: private bool _isFinished

5.  File name should match with class name.
       Ex:  for the class HelloWorld, the file name should be helloworld.cs (or, helloworld.vb) 

6.  Keep private member variables, properties and methods in the top of the file and public members in the bottom.  

7. Use String.Empty instead of “”
      Ex: txtMobile= String.Empty;

8.   8. Avoid having very large files. If a single file has more than 1000 lines of code, it is a good candidate for refactoring. Split them logically into two or more classes.

9. Use StringBuilder class instead of String when you have to manipulate string objects in a loop. The String object works in weird way in .NET. Each time you append a string, it is actually discarding the old string object and recreating a new object, which is a relatively expensive operations.

20 July 2011

Some Coding Standards in .net

1.    Use Meaningful, descriptive words to name variables. Do not use abbreviations.
    Good:
    string address
    int salary
     Not Good:
           string name
       string addr
      int sal

2. Do not use single character variable names like i, n, s etc. Use names like index, temp
     variable 'i' is used for for iterations in loops
        Ex:  for ( int i = 0; i < count; i++ ){....}

3.  Do not use underscores (_) for local variable names. But member variables must be prefixed with underscore (_)

4.  Prefix boolean variables, properties and methods with “is” or similar prefixes.
      Ex: private bool _isFinished

5.  File name should match with class name.
       Ex:  for the class HelloWorld, the file name should be helloworld.cs (or, helloworld.vb) 

6.  Keep private member variables, properties and methods in the top of the file and public members in the bottom.  

7. Use String.Empty instead of “”
      Ex: txtMobile= String.Empty;

8.   8. Avoid having very large files. If a single file has more than 1000 lines of code, it is a good candidate for refactoring. Split them logically into two or more classes.

9. Use StringBuilder class instead of String when you have to manipulate string objects in a loop. The String object works in weird way in .NET. Each time you append a string, it is actually discarding the old string object and recreating a new object, which is a relatively expensive operations.

Naming conventions in .net

Pascal case
The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized.
Example:
BackColor, DataSet
Camel case
The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized.
Example:
numberOfDays, isValid
Uppercase
All letters in the identifier are capitalized.
Example:
ID, PI
1).  Private Variables: _strFirstName, _dsetEmployees
2).  Local Variables: strFirstName, dsetEmployees
3).  Namespace:(Pascal) System.Web.UI, System.Windows.Forms
4).  Class Naming:(Pascal) FileStream, Button
5).  Interface Naming:(Pascal) IServiceProvider, IFormatable
6).  Parameter Naming:(Camel) pTypeName, pNumberOfItems
7).  Method Naming:(Pascal) RemoveAll(), GetCharAt()
7).  Method Parameters:(Camel) void SayHello(string name)....
8).  Property / Enumerations Naming:(Pascal) BackColor, NumberOfItems
9).  Event Naming:(Pascal) public delegate void MouseEventHandler(object sender, MouseEventArgs e);
10).  Exception Naming: catch (Exception ex){ }
11).  Constant Naming: AP_WIN, CONST

19 July 2011

Naming conventions in .net

Pascal case
The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized.
Example:
BackColor, DataSet
Camel case
The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized.
Example:
numberOfDays, isValid
Uppercase
All letters in the identifier are capitalized.
Example:
ID, PI
1).  Private Variables: _strFirstName, _dsetEmployees
2).  Local Variables: strFirstName, dsetEmployees
3).  Namespace:(Pascal) System.Web.UI, System.Windows.Forms
4).  Class Naming:(Pascal) FileStream, Button
5).  Interface Naming:(Pascal) IServiceProvider, IFormatable
6).  Parameter Naming:(Camel) pTypeName, pNumberOfItems
7).  Method Naming:(Pascal) RemoveAll(), GetCharAt()
7).  Method Parameters:(Camel) void SayHello(string name)....
8).  Property / Enumerations Naming:(Pascal) BackColor, NumberOfItems
9).  Event Naming:(Pascal) public delegate void MouseEventHandler(object sender, MouseEventArgs e);
10).  Exception Naming: catch (Exception ex){ }
11).  Constant Naming: AP_WIN, CONST

keyboard key ascii values


<script type="text/javascript">
document.onkeyup = KeyCheck;

function KeyCheck()
{
var KeyID = event.keyCode;
switch(KeyID)
{
case 16:
document.Form1.KeyName.value = "Shift";
break;
case 17:
document.Form1.KeyName.value = "Ctrl";
break;
case 18:
document.Form1.KeyName.value = "Alt";
break;
case 19:
document.Form1.KeyName.value = "Pause";
break;
case 37:
document.Form1.KeyName.value = "Arrow Left";
break;
case 38:
document.Form1.KeyName.value = "Arrow Up";
break;
case 39:
document.Form1.KeyName.value = "Arrow Right";
break;
case 40:
document.Form1.KeyName.value = "Arrow Down";
break;
}
}

how to Insert data of one database table to another database table

INSERT INTO Database2..Table1 SELECT * FROM Database1..Table1

How to restore and backup database in sqlserver using query

For BackUp:
backup database mydb to disk = 'c:\mydb.bak'


For Restore:
restore database mydb from disk = 'c:\mydb.bak'

keyboard key ascii values


<script type="text/javascript">
document.onkeyup = KeyCheck;

function KeyCheck()
{
   var KeyID = event.keyCode;
   switch(KeyID)
   {
      case 16:
      document.Form1.KeyName.value = "Shift";
      break; 
      case 17:
      document.Form1.KeyName.value = "Ctrl";
      break;
      case 18:
      document.Form1.KeyName.value = "Alt";
      break;
      case 19:
      document.Form1.KeyName.value = "Pause";
      break;
      case 37:
      document.Form1.KeyName.value = "Arrow Left";
      break;
      case 38:
      document.Form1.KeyName.value = "Arrow Up";
      break;
      case 39:
      document.Form1.KeyName.value = "Arrow Right";
      break;
      case 40:
      document.Form1.KeyName.value = "Arrow Down";
      break;
   }
}</script>

how to Insert data of one database table to another database table

INSERT INTO Database2..Table1 SELECT * FROM Database1..Table1

How to restore and backup database in sqlserver using query

For BackUp:
backup database mydb to disk = 'c:\mydb.bak'


For Restore:
restore database mydb from disk = 'c:\mydb.bak'

How to copy table structure and data into another database using query

select * into destinationdb..destinationtable from sourcedb..sourcetable

18 July 2011

how to restore database from sqlserver2008 to sqlserver2005

Right click on database of sqlserver2008 that u want to restore-->
Tasks-->
GenerateScripts-->
Next-->
Select Particular database that u want to restore-->
Next-->
Next-->
Select Tables and UserDefined Functions-->
Next-->
Select Tables and Functions-->
Next-->
Select Script to New QueryWindow-->
Next-->
Finish.

It gives a long Query. Copy It, Then execute in Sqlserver2005.
It's working...

How to copy table structure and data into another database using query

select * into destinationdb..destinationtable from sourcedb..sourcetable

how to restore database from sqlserver2008 to sqlserver2005

Right click on database of sqlserver2008 that u want to restore-->
Tasks-->
GenerateScripts-->
Next-->
Select Particular database that u want to restore-->
Next-->
Next-->
Select Tables and UserDefined Functions-->
Next-->
Select Tables and Functions-->
Next-->
Select Script to New QueryWindow-->
Next-->
Finish.

It gives a long Query. Copy It, Then execute in Sqlserver2005.
It's working...