07 March 2012

array in javascript

<p id="div_p"></p>


var array = ["S", "V", "B"];
document.getElementById("div_p").innerHTML = array

var arrIDs=new Array();
arrIDs.push(e);
document.getElementById("div_p").innerHTML=arrIDs.join(',');

var arr = new Array(3);
arr[0] = "a";
arr[1] = "b";
arr[2] = "c";

var array1 = new Array("S", "V", "B");

//for object
var person = {firstName:"John", lastName:"Doe", age:46};


At position 2, add the new items, and remove 1 item:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2, 1, "Lemon", "Kiwi");

The result of fruits will be:
Banana,Orange,Lemon,Kiwi,Mango

31 January 2012

timer countdown in asp.net

Label4.Text = "00";
Label5.Text = "02";
Label6.Text = "00";

        if (Label6.Text == "00" || Label6.Text == "0")
        {
            if (Label5.Text == "00" || Label5.Text == "0")
            {
                if (Label4.Text == "00" || Label4.Text == "0")
                {
                    Timer1.Enabled = false;
                }
                else
                {
                    Label4.Text = (Convert.ToInt32(Label4.Text) - 1).ToString();
                    if (Label4.Text.Trim().Length == 1)
                        Label4.Text = "0" + Label4.Text;
                    Label5.Text = "60";
                }
            }
            else
            {
                Label5.Text = (Convert.ToInt32(Label5.Text) - 1).ToString();
                if (Label5.Text.Trim().Length == 1)
                    Label5.Text = "0" + Label5.Text;
                Label6.Text = "60";
            }
        }
        else
        {
            Label6.Text = (Convert.ToInt32(Label6.Text) - 1).ToString();
            if (Label6.Text.Trim().Length == 1)
                Label6.Text = "0" + Label6.Text;
        }

25 January 2012

Tooltip for dropdownlist items

It is common in most web pages that whole text in dropdown lists cannot be seen due to width limitation. One solution for this would be adding tooltip for the dropdown, so that when selecting a value from dropdown, whole text will be appear as a tooltip. For most of browsers implementing tooltip on dropdown control is not a big deal. We can simply add tooltip text with 'title' attribute. C# implementation for this would be as follows

public void SetToolTip(DropDownList ddl)
{
    if (ddl.Items.Count > 0)
    {
        foreach (ListItem item in ddl.Items)
        {
            item.Attributes.Add("Title", item.Text);
        }
    }
}

21 January 2012

change the database name in sqlserver using query

Supported in SQL Server 2000 and 2005
exec sp_renamedb 'databasename' , 'newdatabasename'

Supported in SQL Server 2005 and later version
ALTER DATABASE 'databasename' MODIFY NAME = 'newdatabasename'

select DB_NAME()
select name from sys.databases

07 January 2012

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

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.



factorial of number in console applications

int count = 1;
Console.Write("Enter Number for factorial: ");
int number = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= number; i++)
{
count = count * i;
}
Console.Write(count);
Console.Read();

or
public static long numfact(long n)
{
if (n <= 1)
return 1;
else
return n * numfact(n - 1);
}
Console.Write(numfact(5));

palindrome in console applications

string str = string.Empty;
Console.WriteLine("Enter a String");
string s = Console.ReadLine();
int i = s.Length;
for (int j = i - 1; j >= 0; j--)
{
    str = str + s[j];
}
if (str == s)
    Console.WriteLine(s + " is palindrome");
else
    Console.WriteLine(s + " is not a palindrome");

06 January 2012

group by and row no in sql

SELECT ROW_NUMBER()  OVER (ORDER BY  ColumnName1) As SrNo, ColumnName1,  ColumnName2 FROM  TableName

SELECT DENSE_RANK()  OVER (ORDER BY  ColumnName1) As SrNo, ColumnName1,  ColumnName2 FROM  TableName

select top 1 ROW_NUMBER()over(orderby col1)as slno,* from tbl1 orderby slno desc

sql syntaxes

Select Statement
SELECT "column_name" FROM "table_name"

Distinct
SELECT DISTINCT "column_name" FROM "table_name"

Where
SELECT "column_name" FROM "table_name" WHERE "condition"

And/Or
SELECT "column_name" FROM "table_name" WHERE "simple condition" {[AND|OR] "simple condition"}+

In
SELECT "column_name" FROM "table_name" WHERE "column_name" IN ('value1', 'value2', ...)

Between
SELECT "column_name" FROM "table_name" WHERE "column_name" BETWEEN 'value1' AND 'value2'

Like
SELECT "column_name" FROM "table_name" WHERE "column_name" LIKE {PATTERN}

Order By
SELECT "column_name" FROM "table_name" [WHERE "condition"] ORDER BY "column_name" [ASC,DESC]

Count
SELECT COUNT("column_name") FROM "table_name"

Group By
SELECT "column_name1", SUM("column_name2") FROM "table_name" GROUP BY "column_name1"

Having
SELECT "column_name1", SUM("column_name2") FROM "table_name" GROUP BY "column_name1" HAVING (arithematic function condition)

Create Table Statement
CREATE TABLE "table_name" ("column 1" "data_type_column_1", "column 2" "data_type_for_column_2",.... )

Drop Table Statement
DROP TABLE "table_name"

Truncate Table Statement
TRUNCATE TABLE "table_name"

Insert Into Statement
INSERT INTO "table_name" ("column1", "column2", ...) VALUES ("value1", "value2", ...)

Update Statement
UPDATE "table_name" SET "column_1" = [new value] WHERE {condition}

Delete From Statement
DELETE FROM "table_name" WHERE {condition}

select--scalar--string, update,insert,delete--nonquery--int

Ref: 

http://www.1keydata.com/sql/sql-syntax.html

http://www.sqlcommands.net/

02 January 2012

C# Features not in Java

•No automatic fall-through from one case block to the next

•Strongly-typed enums

•By reference calls are explicit at caller AND callee

•Method overrides are explicit

•Supports versioning

•Structs (value types)

•Integrated support for properties and events

•Can still use pointers with RAD language

Can share data and use functionality with components written in many different languages

Development tools and Documentation
—Server-side is well supported by both Java and .NET IDEs

—On the client-side .NET IDEs benefit from the fact that .NET CF is so close to .NET  (With Java there are separate IDEs for desktop and mobile application development)

—Compatibility problems between Java vendors

—Java IDEs are slow!

—C# is a richer/more complex language than Java

—Both Java and .NET have well documented API

—Web service documentation

—.NET - MSDN

—Java – Google

—Support for encryption of web services

—.Net CF: HTTPS and SOAP extensions

J2ME: HTTPS, but only in CDC & MIDP 2.0

C# and JAVA


CSharp and JAVA are two different Object Oriented Languages , both have some similarities and differences also . The Csharp and JAVA derived from their own single ancestor Class "Object". All Classes in C# are descended from System.Object Class and in JAVA all classes are subclasses of java.lang.Object Class.

Both C# and JAVA have their own runtime environments . C# source codes are compiled to Microsoft Intermediate Language (MSIL) and during the execution time runs it with the help of runtime environments - Common Language Runtime (CLR). Like that JAVA source codes are compiled to Java Byte Code and during the execution time runs it with the help of runtime environments - Java Virtual Machine (JVM). Both CSharp and JAVA supports native compilation via Just In Time compilers.

More over both C# and JAVA have their own Garbage Collector. In the case of keywords comparison some keywords are similar as well as some keywords are different also. The following are the examples of few similar and different keywords.

Similar Keywords examples

class , new , if , case , for , do , while , continue , int , char , double , null

 

joins example

table1                                  table2

col1 col2                         col3   col4

 1      a                              1       a

 2      b                              2       b

null    c                              3       c

 4     null                           null     d

inner join result:

col1 col2 col3 col4

 1      a     1      a

 2      b     2      b

left outer join result:

col1 col2 col3 col4

  1      a     1     a

  2      b      2    b

 null    c    null  null

  4     null  null  null

full outer join result: 

col1 col2 col3 col4

  1      a     1     a

  2      b      2    b

  null    c    null  null

   4     null  null  null

 null    null    3    c

 null    null   null  d

27 December 2011

ddl in js

opt=document.createElement("OPTION");
document.getElementById('ddlPages').options.add(opt);
opt.text=cnt-1;
opt.value=cnt-1;

17 November 2011

querystring n gv rows in javascript

query string in js: '<%=Request.QueryString["val"]%>';
--------------------------
gridrows in js: Totalrows = parseInt('<%= this.gv1.Rows.Count %>');
--------------------------
var rows = document.getElementById('gv').rows;
for(i=0;i <rows.length;i++)
{
   fd = rows[i].cells[4].innerText;
   rows[i].cells[4].style.display="none";
   rows[i].cells[8].style.display="none";
}

------------------------------------
<asp:Label ID="lblSno" runat="server" Text="<%# Container.DataItemIndex + 1%>"  />    ------------> to get the serial no for the gridview rows after bind the data (take the control to item template field of the grid)