Thursday, May 5, 2016

TextBox Allow only valid decimal value in ASP.NET

In this article I am going to explain , ASP. net text only accept valid decimal value, it allow you to only number and one dot point.

JavaScript Code that allow valid decimal entry

function fun_AllowOnlyAmountAndDot(txt) {
               if (event.keyCode > 47 && event.keyCode < 58 || event.keyCode == 46 || event.keyCode == 44) {
                   var txtbx = document.getElementById(txt);
                   var amount = document.getElementById(txt).value;
                   var present = 0;
                   var count = 0;
 
                   if (amount.indexOf(".", present) || amount.indexOf(".", present + 1));
                   {
                       // alert('0');
                   }
                   do {
                       present = amount.indexOf(".", present);
                       if (present != -1) {
                           count++;
                           present++;
                       }
                   }
                   while (present != -1);
                   if (present == -1 && amount.length == 0 && event.keyCode == 46) {
                       event.keyCode = 0;
                       return false;
                   }
                   if (present == -1 && amount.length == 0 && event.keyCode == 44) {
                       event.keyCode = 0;
                       //alert("Wrong position of decimal point not  allowed !!");
                       return false;
                   }
                   if (count >= 1 && event.keyCode == 46) {
 
                       event.keyCode = 0;
                       //alert("Only one decimal point is allowed !!");
                       return false;
                   }
                   if (count >= 1 && event.keyCode == 44) {
 
                       event.keyCode = 0;
                       //alert("Only one decimal point is allowed !!");
                       return false;
                   }
                   if (count == 1) {
                       var lastdigits = amount.substring(amount.indexOf(".") + 1, amount.length);
                       if (lastdigits.length >= 2) {
                           //alert("Two decimal places only allowed");
                           event.keyCode = 0;
                           return false;
                       }
                   }
                   return true;
               }
               else {
                   event.keyCode = 0;
                   //alert("Only Numbers with dot allowed !!");
                   return false;
               }
           }
 

Function calling from textbox


<asp:TextBox ID="txtvalidenter" runat="server"  CssClass="inrinpt"  onkeypress="return fun_AllowOnlyAmountAndDot(this.id);" ></asp:TextBox>

SQL question and answer for fresher

What is SQL?
SQL is stand for structured query language designed for communicating with database

What are the different types of SQL statement?
The SQL statement is given below:
DDL – DDL is stand for Data definition language used to define the data For example Create, Alter, Drop, truncate table.
DML – DML is stand for Data manipulation language is used to manipulate data itself for example insert, update, delete, retrieving data from table.
DCL – DCL is stand for data control language is used to control the visibility of data for example granting database access and set privileges and set privileges to create table. Grant, Deny, revoke commands are used in DCL.

What is a field in the database?
A field is an area where record is kept for a specific piece of data for example client name, client address etc.

What is a record in the database?
A record is the collection of fields for example salary of an employee

What is the table in database?
A table is the collection of record for example emp table, salary table etc.

What is the difference between clustered and Non-clustered index?
Clustered index physically sort all rows while Non clustered index does not sort.
One table contain only one clustered index while in Non-clustered index there is no such restriction
In clustered index the leaf level pages are the actual data pages of the table while in Non-clustered index does not contain data pages while it contain pointer to the data pages.

 What is the difference between primary key and unique Key and Foreign Key?
Primary key and unique key both enforce uniqueness of the column, primary key create a clustered index on the column while unique key create Non clustered index on the column, the major difference between the primary key and unique key is that  primary key does not allow Nulls, while unique key allows one NULL values.
Foreign key in one table points to the primary key to the another table .

What is the difference among delete and truncate and drop commands?
Truncate
Truncate removes all rows from a table but table structure, its column, constraints, indexes do not remove
Truncate cannot be rolled back
Truncate is DDL commands
Truncate reset identity of table
Delete
Delete is used to delete rows in the table also used where clause to remove the user if we don’t use where clause then all rows will be removed
Delete commands is used with or without where clause
Delete can be rolled back
Delete is DML commands
It does not reset identity of the table
Drop
Drop commands are used to remove object from the table by using drop commands all the rows deleted and also structure of the table from database is deleted

What is the difference between the having clause and where clause?
Having clause can be used only with the SELECT statement it is used in GROUP BY clause if we don’t use GROUP BY clause HABING work just like a Where Clause. Having clause is used only with the group by function while where clause is applied to each row.

What is check constraints?
The check constraints are used to enforce domain integrity and it is used to limit the value which is placed in the column.

What is NOT NULL constraints?
Not Null constraints is just like check constraints it enforce the column will does not accept  null values.

What is the stored procedure?
Stored procedure are the group of SQL statement which run all the SQL statement in a single unit it is precompiled object if we call to stored procedure then there is no need to compile again.

What is SQL injection?
This is the problem by injecting the SQL command illegal operation can be performed the solution of the problem is that use parameterized query.

What is transaction?
Transaction is used to proceed multiple SQL statement into single logical unit.

Tuesday, May 3, 2016

WAP to print Fibonacci numbers below 100

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication12
{
    class class1
    {
        public static int Fib(int n)
        {
            int a = 0;
            int b = 1;
      
            for (int i = 0; i < n; i++)
            {
                int temp = a;
                a = b;
                b = temp + b;
            }
            return a;
        }

        static void Main()
        {
            for (int i = 0; i < 12; i++)
            {
                Console.WriteLine(Fib(i));
                Console.ReadKey();
            }
        }
    }
}
Output :

Monday, May 2, 2016

Data types in c#



In C# data types are categories in the following types:
Value Type
Reference Type
Pointer Type

Value type – Value type variables can be assign a value directly. The following table shows the value types in c#

Type
Represents
Range
Default Value
bool
Boolean value
True or false
False
byte
8-bit unsigned integer
0 to 255
0
char
16-bit Unicode character
U +0000 to U +ffff
‘\0’
decimal
128 bit data type
-1.0 X 10-7.9X1028
0.0M
double
64 bit double-precision value
(+/-)5.0 x 10-324 to (+/-)1.7 x 10308
0.0D
float
32 bit single precision value
-3.4 x 1038 to + 3.4 x 1038
0.0F

int
32-bit signed integer type
-2,147,483,648 to 2,147,483,647
0
long
64 –bit signed integer type
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
0L
sbyte
8-bit signed integer type
-128 to 127
0
short
16-bit signed integer type
-32768 to 32768
0


Reference Type – the reference type do not contain the data directly, while they contain the reference to the variable. The build-in reference type are : object, and string.

Object type – The object types can be assigned values of any other types, value types, reference types, when we assign value it need conversion ,conversion of value type to reference type is called boxing and reference type to value type is called unboxing.

Obj o;
O=10; this is called boxing

String Types - string type assign any string value to a variable
For Example – string s=”Dot Net darpan”;

Pointer type – pointer type variables store the address of another variable. Syntax of pointer type is given below:

type* identifier;

For Example –
Char* dotnet;
int * darpan;




Sunday, May 1, 2016

Group Functions in SQL

These functions take a group of rows into consideration and returns a single value as an output.

Count (*)

It returns the no. of rows that can be retrieved by the given 'select' statement.

Example

select Count (*) from Emp where depno = 30
select Count (*) from Emp where Job = 'Clerk'

Count (colname)

It returns the no. of Not Null values that are present in the specified column.

Example
select Count (comm) from Emp
select Count (M62) from Emp

NOTE

All the Group functions will not take Null values into consideration.

Sum (colname)

It returns the sum of the specified column.

Example

select Sum (sal) from Emp
select Sum (comm) from Emp

Avg (colname)

It returns the average of the specified column i.e., Sum(colname) / Count(colname)

Example

select Avg (sal) from Emp
select Avg (comm) from Emp

Max (colname)

It returns the highest value of the specified column.

Example

select Max (sal) from Emp

Min (colname)

It returns the least value of the specified column. 

Example

select Min (sal) from Emp

Stdev (colname)

It returns the standard deviation of the specified column.

Example

select Stdev (sal) from Emp

Var (colname)

It returns the variance of the specified column.

Example

select Var (sal) from Emp

Distinct function

It returns the values of the specified column by eliminating duplicates.

Example


select Distinct job from Emp