How to check if a variable is NOT undefined

Checking undefined is not work when we go normal if statement, As like below

var id=$('#txt').val();

if(id != 'undefined')
{
// Our Code
}

"id" is var type, i.e mean unknown type, such as whether "id" is string, numeric, or even undefined.  
if "txt" is not defined in the page, then its value is  undefined is a one of type, so we shall check the type of operand with value.

By using "typeof" operator we resolve above issue. The "typeof" operator in JavaScript/Jquery allows you to probe the data type of its operand.

var item = 10;
alert(typeof item); This returns the type of item not value.


if(typeof id != 'undefined')
{
// Our Code
} 

I hope this will help you to resolve the problem.

What's the main difference between int.Parse() and Convert.ToInt32

string str = "199"

int.Parse(str)

  1. This method converts the string to integer. 
  2. If string variable 'str' is null, then it will throw ArgumentNullException. 
  3. If string 'str' has out of integer ranges, then it will throw OverflowException.
  4. If string 'str' is other than integer value, then it will throw FormatException. 


Convert.ToInt32(str)

  1. This method converts the string to integer. 
  2. If string str is null, then it will return 0 rather than throw ArgumentNullException.
  3. If string str represents out of integer ranges, then it will throw OverflowException. 
  4. If string str is other than integer value, then it will throw FormatException. 


What's the main difference between int.Parse() and Convert.ToInt32

string str = "199"

int.Parse(str)

  • This method converts the string to integer. 
  • If string variable 'str' is null, then it will throw ArgumentNullException. 
  • If string 'str' has out of integer ranges, then it will throw OverflowException.
  • If string 'str' is other than integer value, then it will throw FormatException. 


Convert.ToInt32(str)

  • This method converts the string to integer. 
  • If string str is null, then it will return 0 rather than throw ArgumentNullException.
  • If string str represents out of integer ranges, then it will throw OverflowException. 
  • If string str is other than integer value, then it will throw FormatException. 

find number of days in a month in sql



DECLARE @mydate DATETIME

SET @mydate = '1986/01/21'

SELECT DAY(DATEADD(DAY,-DAY(@mydate),DATEADD(MONTH,1,@mydate))) as DAYSCOUNT


Above query will return number days in a month. Actually it return last date of given month. This is simplest way to get number of days in a given month.


Attribute 'ng-app' is not a valid attribute of element 'html'

This is just a warning. You haven't enabled html5 in your application.That s why you are receiving this validation warnings.

Here i gave solution to rid out from this warnings.

After opened your MS VS, Select Tools->Options ->Text Editor- >HTML->Validation, Choose html5 in list, then restart your project.

If you are not find html5 in the list, you need to install html5, then do above step. Click here to down html5.

Again you are receiving such that warining, then prepend data- to the attribute name (e.g. data-ng-app, the warning lines gets disappear.


$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$


HOW YOU DEFINE WEB.CONFIG ? CLICK HERE 2 FIND ANSWER


$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

Element section is not supported in visual studio

You haven't enabled html5 in your application.That s why you are receiving this validation warnings.

Here i gave solution to rid out from this warnings. 

After opened your MS VS, Select Tools->Options ->Text Editor- >HTML->Validation, Choose html5 in list, then restart your project.

If you are not find html5 in the list, you need to install html5, then do above step. Click here to down html5.

CASCADE in SQL SERVER with example

Use the ON DELETE CASCADE option if you want rows deleted in the child table when corresponding rows are deleted in the parent table. If you do not specify cascading deletes, the default behavior of the database server prevents you from deleting data in a table if other tables reference it.

If you specify this option, when you delete a row in the parent table, the database server also deletes any rows associated with that row (foreign keys) in a child table. The advantage of the ON DELETE CASCADE option is that it allows you to reduce the quantity of SQL statements needed to perform delete actions.

select * from dbo.ProductDetails
select * from dbo.Products

CREATE TABLE [dbo].[Products](
[ProductID] [int] NOT NULL,
[ProductDesc] [varchar](50) NOT NULL,
CONSTRAINT [PK_Products] PRIMARY KEY CLUSTERED
(
[ProductID] ASC
)) ON [PRIMARY]

CREATE TABLE [dbo].[ProductDetails](
[ProductDetailID] [int] NOT NULL,
[ProductID] [int] NOT NULL,
[Total] [int] NOT NULL,
CONSTRAINT [PK_ProductDetails] PRIMARY KEY CLUSTERED
(
[ProductDetailID] ASC
)) ON [PRIMARY]
GO

ALTER TABLE [dbo].[ProductDetails] WITH CHECK ADD CONSTRAINT
[FK_ProductDetails_Products] FOREIGN KEY([ProductID])
REFERENCES [dbo].[Products] ([ProductID])
ON UPDATE CASCADE
ON DELETE CASCADE

INSERT INTO Products (ProductID, ProductDesc)
SELECT 1, 'Bike'
UNION ALL
SELECT 2, 'Car'
UNION ALL
SELECT 3, 'Books'

INSERT INTO ProductDetails
([ProductDetailID],[ProductID],[Total])
SELECT 1, 1, 200
UNION ALL
SELECT 2, 1, 100
UNION ALL
SELECT 3, 1, 111
UNION ALL
SELECT 4, 2, 200
UNION ALL
SELECT 5, 3, 100
UNION ALL
SELECT 6, 3, 100
UNION ALL
SELECT 7, 3, 200

SELECT *
FROM Products
SELECT *
FROM ProductDetails

DELETE
FROM Products
WHERE ProductID = 1


DROP TABLE ProductDetails
DROP TABLE Products