What is a View in sql server and its advantages ?

 

A view is nothing more than a saved query.  A view can also be considered as a virtual table.

DeptId DeptName
1 IT
2 Payroll
3 HR
4 Admin

 

Id Name Salary Gender DepartmentId
1 Jhon 5000 Male 3
2 Mike 3400 Male 2
3 Pam 6000 Female 1
4 Todd 4800 Male 4
5 Sara 3200 Female 1
6 Ben 4800 Male 3

Select Query

Select Id, Name, Salary, Gender, DeptName

From tblEmployee

Join tblDepartment

On tblEmployee.DepartmentId=tblDepartment.DeptID

Result

Id Name Salary Gender DeptName
1 Jhon 5000 Male HR
2 Mike 3400 Male Payroll
3 Pam 6000 Female IT
4 Todd 4800 Male Admin
5 Sara 3200 Female IT
6 Ben 4800 Male HR

Creating View using select Query

Create View vWEmployeesByDepartment

As

Select Id, Name, Salary, Gender, DeptName

From tblEmployee

Join tblDepartment

On tblEmployee.DepartmentId=tblDepartment.DeptID

Select * from  vWEmployeesByDepartment

Result

Id Name Salary Gender DeptName
1 Jhon 5000 Male HR
2 Mike 3400 Male Payroll
3 Pam 6000 Female IT
4 Todd 4800 Male Admin
5 Sara 3200 Female IT
6 Ben 4800 Male HR

Advantages of views

  • Views can be used to reduce the complexity of the database schema
  • Views can be used as a mechanism to implement row and column level security

Example if IT department employees only to show

Create View vWITEmployeesByDepartment

As

Select Id, Name, Salary, Gender, DeptName

From tblEmployee

Join tblDepartment

On tblEmployee.DepartmentId=tblDepartment.DeptID

Where tblDepartment.DeptName=’IT’

Select * from  vWITEmployeesByDepartment

Result

Id Name Salary Gender DeptName
3 Pam 6000 Female IT
5 Sara 3200 Female IT

Example if salary to hide

Create View vWNonconfedentialdata

As

Select Id, Name,  Gender, DeptName

From tblEmployee

Join tblDepartment

On tblEmployee.DepartmentId=tblDepartment.DeptID

Select * from vWNonconfedentialdata

Result

Id Name Gender DeptName
1 Jhon Male HR
2 Mike Male Payroll
3 Pam Female IT
4 Todd Male Admin
5 Sara Female IT
6 Ben Male HR
  • Views can be used to present aggregated data and hide detailed data.

Example

Create view VwsummarizedData

As

select DeptName, Count(ID) as Total

From tblEmployee

Join tblDepartment

On tblEmployee.DepartmentId=tblDepartment.DeptID

Group by DeptName

 

Select * from VwsummarizedData

Result

DeptName Total
Admin 1
HR 2
IT 2
Payroll 1

 

To modify view – ALTER VIEW statement

To droop a view – DROP VIEW viewname

How to use date in javascript and the different date methods?

The Date object is a datatype built into the JavaScript language. Date objects are created with the new Date( ). Date expression with arguments

  • new Date( )
  • new Date(datestring)
  • new Date(year,month,date[,hour,minute,second,millisecond ])

Description of the parameters:

  • No Argument:With no arguments, the Date( ) constructor creates a Date object set to the current date and time.
  • Datestring: When one string argument is passed, it is a string representation of a date, in the format accepted by the Date.parse( ) method.
  •  7 agruments: To use the last form of constructor given above, Here is the description of each argument:
    • year: Integer value representing the year. For compatibility (in order to avoid the Y2K problem), you should always specify the year in full; use 1998, rather than 98.
    • month: Integer value representing the month, beginning with 0 for January to 11 for December.
    • date: Integer value representing the day of the month.
    • hour: Integer value representing the hour of the day (24-hour scale).
    • minute: Integer value representing the minute segment of a time reading.
    • second: Integer value representing the second segment of a time reading.
    • millisecond: Integer value representing the millisecond segment of a time

Date Methods:

  •  Date()            – Returns today’s date and time
  • getDate()        -Returns the day of the month for the specified date according to local time.
  • getDay()         -Returns the day of the week for the specified date according to local time.
  • getFullYear() -Returns the year of the specified date according to local time.
  • getHours()      -Returns the hour in the specified date according to local time.
  • getMonth()     -Returns the month in the specified date according to local time.
  • getSeconds()  -Returns the seconds in the specified date according to local time.
  • getTime()        -Returns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC.
  • getTimezoneOffset()   -Returns the time-zone offset in minutes for the current locale.
  • getUTCDate()        -Returns the day (date) of the month in the specified date according to universal time.
  • getUTCDay()          -Returns the day of the week in the specified date according to universal time.
  • getUTCFullYear()   -Returns the year in the specified date according to universal time.
  • getUTCHours()      -Returns the hours in the specified date according to universal time.
  • getUTCMilliseconds()     -Returns the milliseconds in the specified date according to universal time.
  • getUTCMinutes()            -Returns the minutes in the specified date according to universal time.
  • getUTCMonth()  -Returns the month in the specified date according to universal time.
  • getUTCSeconds()    -Returns the seconds in the specified date according to universal time.

What are the different action method’s return type?

1) ViewResult : Used to return a view to render html in the browser. this is the most common used action result

2)PartialViewResult: Similar to view result, it returns a partial view.

3) ContentResult: Used to return any type of content. By default it is used to return plain text but the actual content type can be explicitly defined

4) EmptyResult: this is equivalent to void method,it is by definition an action result object,but it does nothing.

5)FileResult:Used to return binary content.

6)HttpUnauthroizedResult: You can return an HttpUnauthrized result when the request tries to access restricted content that, for example its not available to anonymous user.

7)JavaScriptResult:Used to  return JavaScript code.

8)JsonResult: Used  to return any object in JavaScript Object Notation(JSON) format.

9)RedirectRresult:Used to perform an HTTP redirect to another URL.you can define it as temporary (code 302) or permanent (code 301)  HTTP redirect.

10)RedirectToRouteResult: used to perform an HTTP redirect ,but to specific route rather than a URL

 

 

The requested page cannot be accessed because the related configuration data for the page is invalid in MVC

The requested page cannot be accessed

The error message “The requested page cannot be accessed because the related configuration data for the page is invalid in MVC”  is occurred due to invalid code in the web.config file. Invalid code in the sense you may given a invalid tag like for <connectionString> you may given <constr>. it makes the error we should use the current xml tag names.

Please see the below examples

Actual tag code for connection string

<connectionString>

you may be made mistake like

<connectionstring>

See the above example the ‘S’ letter for the two example is different because the web.config file xml tags are case sensitive. it should follow the visual studio rules to avoid errors.

In web.config xml file we should specify the tags currently according to the visual studio needs.

if anything wrong in the web.config file you will get the error like

The requested page cannot be accessed because the related configuration data for the page is invalid in MVC

 

How to move second div to first in mobile view using css ?

we may need to show divs in different ways in mobile views. Like the same now consider a situation there is a requirement to move the second div to first and first div to second in mobile view. for web view it is normal.

You can find below code that helps to move second div to first and first div to second using css.

If you want to test

Step 1 : the code just copy the code
Step 2 : open a editor or notepad and paste the code
Step 3 : save the code in any location with file extension “.html” , Eg : index.html
Step 4 : open the file in a browser and check the mobile view.

Move second div to first and first div to second using css

<html>
<style>
.parent{
width:100%;
}

.parent div
{
width:50%;
float:left;

}
@media only screen and (max-width: 767px) {
   
    .parent 
    {   
       display: table;
    }
    .parent div{width: 100%;float: none}
    .leftColumn
    {
        display:table-footer-group; 
  color:red;
     
  
    }
    .rightColumn
    {
        display: table-header-group;
      
    } 
 
 }
</style>
<body>

<div class="parent">
 <div class="leftColumn">
 This is the first div
 </div>

 <div class="rightColumn">
 This is the second div
 </div>
<div>

</body>

</html>