Tuesday 25 October 2016

HOW TO VALIDATE INPUT FIELD NUMERIC WITH FIXED NUMBER.

HOW TO VALIDATE INPUT FIELD NUMERIC WITH FIXED NUMBER OF DIGIT


Validation for Number(CONTACT NUMBER (10 Digit max )).

--------------------------------------------------------------------------------------------------------------------------
<script language="javascript" type="text/javascript">

    function fixedlength(textboxID, keyEvent, maxlength) {
        //validation for digits upto 'maxlength' defined by caller function
        if (textboxID.value.length > maxlength) {
            textboxID.value = textboxID.value.substr(0, maxlength);
        }
        else if (textboxID.value.length < maxlength || textboxID.value.length == maxlength) {
            textboxID.value = textboxID.value.replace(/[^\d]+/g, '');
            return true;
        }
        else
            return false;
    }

    function CheckMax(controlname) {
        var num = document.getElementById('<%=txtAmount.ClientID %>').value;
        if (num > 100 || num <= 0) {
            alert('Please Enter Value between 1 to 100');
            document.getElementById('<%=txtAmount.ClientID %>').value = '';
               document.getElementById('<%=txtAmount.ClientID %>').focus();
            return false;
        }
     return true;
 }
</script>
--------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------

<form id="form1" runat="server" action="ValidateFormWebUI.aspx" autocomplete="off">
        
            
            <div class="submain">
                <table class="tblform">
                    <tbody>
                          <tr>
                            <td class="textfield" title="Enter Name">Name</td>
                            <td class="textfield">
                                <input id="txtName" name="NAME" class="InputField" maxlength="150" type="text" value="" /></td>
                        </tr>
                        <tr>
                            <td class="textfield" title="Enter Name">Contact</td>
                            <td class="textfield"><asp:textbox class="InputField" id="txtContactNo" runat="server" maxlength="10" onblur="return fixedlength(this, event, 10);" onkeypress="return fixedlength(this, event, 10);" onkeyup="return fixedlength(this, event, 10);"></asp:textbox></td>
                        </tr>
                         <tr>
                            <td class="textfield" title="Enter Name">Amount (0-100)</td>
                            <td class="textfield"><asp:textbox class="InputField" id="txtAmount" runat="server" maxlength="3"></asp:textbox></td>
                        </tr>
                    </tbody>
                </table>
            </div>
       
    </form>

Monday 5 September 2016

SQL JOINS with Examples

SQL JOINS with Examples


SQL JOIN :- The SQL Joins clause is used to combine records from two or more tables in a database. A JOIN is a means for combining fields from two tables by using values common to each.

INNER JOIN:- An SQL INNER JOIN returns all rows from multiple tables where the join condition is met.

NOTE :- IN Example Using Table find in below link page.


Example:- 

SELECT Emp1.ID,Emp1.Name,User1.ID,User1.City
FROM Emp1
INNER JOIN User1
ON Emp1.ID=User1.ID;



LEFT JOIN :- The SQL LEFT JOIN returns all rows from the left table, even if there are no matches in the right table.

EXAMPLE :- 

SELECT Emp1.ID,Emp1.Name,Emp1.Company,User1.ID,User1.Name,User1.City
FROM Emp1
LEFT JOIN User1
ON Emp1.ID=User1.ID;



RIGHT JOIN:- The SQL RIGHT JOIN returns all rows from the right table, even if there are no matches in the left table. 

EXAMPLE :- 

SELECT Emp1.ID,Emp1.Name,Emp1.Company,User1.ID,User1.Name,User1.City
FROM Emp1
RIGHT JOIN User1
ON Emp1.ID=User1.ID;




Create , Insert , and Select Query in SQL

Create , Insert , and Select Query in SQL

Create :- The CREATE TABLE statement is used to create a table in a database.

SYNTAX :- 
                CREATE TABLE table_name(
                                      column1 datatype,
                                      column2 datatype,
                                      column3 datatype,
                                      .....
                                      columnN datatype,
                                      PRIMARY KEY( one or more columns )
                                     );
EXAMPLE :-

CREATE TABLE Emp1(
ID int not null,
Name varchar(50),
Company varchar(50),
Salary varchar(50),
);

CREATE TABLE User1(
ID int not null,
Name varchar(50),
City varchar(50),
);




 INSERT :- The SQL INSERT INTO Statement is used to add new rows of data to a table in the database.

SYNTAX :- INSERT INTO TABLE_NAME
                                       (column1, column2, column3,...columnN)
                             VALUES
                                     (value1, value2, value3,...valueN);
EXAMPLE :-
      
INSERT INTO Emp1 VALUES (1,'RAM','TCS','30000'),
(2,'SHYAM','TCS','78500'),
(3,'MOHAN','HP','58000'),
(4,'GEETA','HP','85000'),
(5,'SITA','WIPRO','44000'),
(6,'LAKSHMAN','WIPRO','5500'),
(7,'RAHIM','DELL','43000'),
(8,'AKASH','DELL','34000'),
(9,'RANI','HCL','54000'),
(10,'SOHAN','HCL','45000');

INSERT INTO User1 VALUES (1,'RAM','Nagpur'),
(2,'SHYAM','Pune'),
(3,'MOHAN','Dehradun'),
(4,'GEETA','Himachal'),
(5,'SITA','Nainital'),
(6,'LAKSHMAN','Punjab'),
(7,'RAHIM','Hariyana'),
(8,'AKASH','Noida'),
(9,'RANI','Delhi'),

(10,'SOHAN','Mumbai');


SELECT :- SQL SELECT statement is used to fetch the data from a database table which returns data in the form of result table. These result tables are called result-sets.

SYNTAX :- SELECT column1, column2, columnN FROM table_name;

EXAMPLE:-

            SELECT * FROM Emp1;


            SELECT * FROM User1;



Thursday 1 September 2016

C# Interviews Questions and Answers for 0 to 1 year experience

C# Interviews Questions and Answer

1. What is C#?
C# is an object oriented type safe and managed language that is compiled by .Net framework to generate Microsoft Intermediate Language.
2.  What is a Class?
a set or category of things having some property or attribute in common and differentiated from others by kind, type, or quality.

3. What is an object?  
An object is an instance of a class through which we access the methods of that class. In C# “New” keyword is used to create an object. A class that creates an object in memory will contain the information about the methods, variables and behavior of that class.
4. What is Constructors? 
A constructor is a member function in a class that has the same name as its class. The constructor is automatically invoked whenever an object class is created. It constructs the values of data members while initializing the class.
5. What is the use of using statement in C#?  
The using block is used to obtain a resource and use it and then automatically dispose of when the execution of block completed.
6. What is an interface class?  
Interface is an abstract class which has only public abstract methods and the methods only have the declaration and not the definition. These abstract methods must be implemented in the inherited classes.
7. What are value types and reference types?  
     Value types are stored in the Stack.
      e.g:-   int, enum , byte, decimal, double, float, long
      Reference types stored on heap.
       e.g:-  string, class, interface, object
8. What are sealed classes in C#?  
We create sealed classes when we want to restrict the class to be inherited. Sealed modifier used to prevent derivation from a class. If we forcefully specify a sealed class as base class then a compile-time error occurs.
9. What’s the difference between an interface and abstract class?
Interfaces have all the methods having only declaration but no definition. In an abstract class, we can have some concrete methods. In an interface class, all the methods are public. An abstract class may have private methods.
10.What is the difference between Finalize() and Dispose() methods?
Dispose() is called when we want for an object to release any unmanaged resources with them. On the other hand Finalize() is used for the same purpose but it doesn’t assure the garbage collection of an object.
11. What are generics in C#.NET?
Generics are used to make reusable code classes to decrease the code redundancy, increase type safety and performance. Using generics, we can create collection classes. To create generic collection, System.Collections.Generic namespace should be used instead of classes such as ArrayList in the System.Collections namespace. Generics promotes the usage of parameterized types.
12. What are delegates?
Delegates are same are function pointers in C++ but the only difference is that they are type safe unlike function pointers. Delegates are required because they can be used to write much more generic type safe functions.
14.  What is the difference between method overriding and method overloading?
In method overriding, we change the method definition in the derived class that changes the method behavior. Method overloading is creating a method with the same name within the same class having different signatures.
15.  What are the different ways a method can be overloaded?
Methods can be overloaded using different data types for parameter, different order of parameters, and different number of parameters.
16. What are indexers in C# .NET?
Indexers are known as smart arrays in C#. It allows the instances of a class to be indexed in the same way as array.
e.g.:- public int this[int index]    // Indexer declaration
17. What is difference between the “throw” and “throw ex” in .NET?
“Throw” statement preserves original error stack whereas “throw ex” have the stack trace from their throw point. It is always advised to use “throw” because it provides more accurate error information.
18. How to implement singleton design pattern in C#?
In singleton pattern, a class can only have one instance and provides access point to it globally.
e.g:- Public sealed class Singleton
            {
                 Private static readonly Singleton _objSingleton = new Singleton();
             }
19. Explain use of Abstract and Sealed Classes in C#?
The abstract keyword enables you to create classes and class members that are incomplete and must be implemented in a derived class.

The sealed keyword enables you to prevent the inheritance of a class or certain class members that were previously marked virtual.
20.  Which are Access Modifiers available in C#?
All types and type members have an accessibility level, which controls whether they can be used from other code in your assembly or other assemblies.
You can use the following access modifiers to specify the accessibility of a type or member when you declare it:
public: The type or member can be accessed by any other code in the same assembly or another assembly that references it.
private: The type or member can be accessed only by code in the same class or struct.
protected: The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.
internal: The type or member can be accessed by any code in the same assembly, but not from another assembly.
21. Data Types in C#?
bool, byte , char, decimal , double, float, int, long, sbyte , short, uint, ulong, ushort.


Factorial of a Number

Recently Viewed