Q.
Can Static class inherited from derived/child Classes in c sharp?
A.
No
Let’s
explorer it...
Step
1:- Create a static class and inherit the static class with derived/child class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StaticClass
{
static class BaseClass
{
public static void Display()
{
Console.WriteLine("Base
class Display()");
}
}
class ChildClass : BaseClass
{
static void Main(string[] args)
{
BaseClass.Display();
}
}
}
When you inherit the static class with derived class, you
will get the compile time error 'StaticClass.ChildClass':
cannot derive from static class StaticClass.BaseClass'.
Note:-
- When class is marked static, you
cannot declare instance members in a static class.
- Static members directly accessible
with class name.
Q.
What is the default modifier of class, method and properties in c sharp?
A.
Class
default modifier is internal
Method
default modifier is private
Properties default
modifier is private
Q.
If class A contains class B and class B marked private and its member’s marked
public, so can class A access the class B member’s?
A. No, class B is
inaccessible due to its protection level.
Let’s
explorer it...
Step
1:- Create a class A and inside class A create class B and marked class B
private.
class A
{
private class B
{
public void Display()
{
Console.WriteLine("Class
B Display()");
}
}
}
class C
{
static void Main(string[] args)
{
A objA
= new A();
A.B objB
= new A.B();
objB.Display();
}
}
You
are not able to create the object of class B due to its protection level.
Q.
What is SQL Commands?
A. Data Definition Language
(DDL)
CREATE,
ALTER, DROP
Data
Manipulation Language (DML)
SELECT,
INSERT, UPDATE, and DELETE.
Data
Control Language (DCL)
GRANT
and REVOKE.
Transaction
Control Language (TCL)
COMMIT,
ROLLBACK, SAVEPOINT and SET TRANSACTION.
Q.
Can we create a trigger on view? Or can we insert a record in view?
A.
Yes, we can create only instead of trigger on view.
Let’s
explorer it...
Step
1:- Create Department and Employee table
CREATE TABLE Department
(
DeptId int identity,
DeptName varchar(10)
)
CREATE TABLE Employee
(
EmpId int identity,
DeptId int,
EmpName varchar(10)
)
select * from Department
select * from Employee
Step
2:- Create View
create view View1
as
select a.DeptId,a.DeptName,b.EmpId,b.EmpName
from Department a
inner join Employee b on a.DeptId = b.DeptId
select * from View1
Step
3:- Insert record to View
insert into View1 values(1,'Account',2,'A')
You
will get the following error:-
Msg
4405, Level 16, State 1, Line 30
View
or function 'View1' is not updatable because the modification affects multiple
base tables.
Step
4:- Create trigger on View
create trigger trg_Insert
on View1
instead of insert
as
begin
insert into Department select DeptName from Inserted
insert into Employee select DeptId,EmpName from Inserted
end
insert into View1 values(1,'Account',1,'Ram')
(1
row(s) affected)
(1
row(s) affected)
(1
row(s) affected)
select * from View1
DeptId
|
DeptName
|
EmpId
|
EmpName
|
1
|
Account
|
1
|
Ram
|
select * from Department
DeptId
|
DeptName
|
1
|
Account
|
select * from Employee
EmpId
|
DeptId
|
EmpName
|
1
|
1
|
Ram
|
drop table Department
drop table Employee
drop trigger trg_Insert
drop view View1
Q.
ASP.NET Page Life Cycle
A.
Stage
|
Description
|
Page request
|
The page request occurs before the page life cycle begins. When the page
is requested by a user, ASP.NET determines whether the page needs to be
parsed and compiled (therefore beginning the life of a page), or whether a
cached version of the page can be sent in response without running the page.
|
Start
|
In the start stage, page properties such as Request and Response are
set. At this stage, the page also determines whether the request is a
postback or a new request and sets the IsPostBack property.
The page also sets the UICulture property.
|
Initialization
|
During page initialization, controls on the page are available and each
control's UniqueID property
is set. A master page and themes are also applied to the page if applicable.
If the current request is a postback, the postback data has not yet been
loaded and control property values have not been restored to the values from
view state.
|
Load
|
During load, if the current request is a postback, control properties are
loaded with information recovered from view state and control state.
|
Postback event handling
|
If the request is a postback, control event handlers are called. After
that, the Validate method
of all validator controls is called, which sets the IsValid property
of individual validator controls and of the page. (There is an exception to
this sequence: the handler for the event that caused validation is called
after validation.)
|
Rendering
|
Before rendering, view state is saved for the page and all controls.
During the rendering stage, the page calls the Render method
for each control, providing a text writer that writes its output to the OutputStream object
of the page's Response property.
|
Unload
|
Source
Q.
How to get the total number of counts of Ram in both the table?
A.
CREATE TABLE #Table1
(
Name varchar(10)
)
CREATE TABLE #Table2
(
Name varchar(10)
)
insert into #Table1 values('Ram')
insert into #Table1 values('Shyam')
insert into #Table1 values('Ghanshyam')
insert into #Table1 values('Gopal')
insert into #Table1 values('Ram')
insert into #Table2 values('Ram')
insert into #Table2 values('Shyam')
insert into #Table2 values('Ghanshyam')
insert into #Table2 values('Gopal')
insert into #Table2 values('Ram')
select * from #Table1
Name
|
Ram
|
Shyam
|
Ghanshyam
|
Gopal
|
Ram
|
select * from #Table2
Name
|
Ram
|
Shyam
|
Ghanshyam
|
Gopal
|
Ram
|
SELECT COUNT(*)
FROM
(
SELECT NAME FROM #Table1
UNION ALL
SELECT Name FROM #Table2
) t
WHERE t.Name = 'Ram'
Results
4
drop table #Table1
drop table #Table2
Q.
Where is GAC (Global Assembly Cache) located?
A.
Starting
with the .NET Framework 4, the default location for the global assembly cache
is %windir%\Microsoft.NET\assembly.
In
earlier versions of the .NET Framework, the default location is
%windir%\assembly.
.Net
Framework 4 and above
C:\Windows\Microsoft.NET\assembly
or %windir%\Microsoft.NET\assembly
Below
.Net Framework 4
C:\Windows\assembly
or %windir%\assembly
Source
Q.
How to install the assemblies in GAC?
A.
Go
to Start => All Programs => Visual Studio 2013 => Visual Studio Tools
=> Developer Command Prompt for VS2013
Note:-
You
must have administrator privileges to use Gacutil.exe
Run
following command
gacutil
-i Complete Path of DLL
If
you get the following error:
Failure
adding assembly to the cache: Attempt to install an assembly without a strong
name
Go
to below URL and follow the given step
If
you completed the given step, go to Solution Explorer, from the Project menu.
You will see .snk file is created.
Now,
run the same command again. You will get the following successful message.
Assembly
successfully added to the cache
To
see added assemblies in GAC
Go
to C:\Windows\Microsoft.NET\assembly\GAC_MSIL
Note:-
The
folder name is created in GAC_MSIL folder with your Project namespace name.
For
more info and how to uninstall the assemblies?
Visit
following link
Q.
Function vs. Stored Procedure in SQL Server
A.
The
Function has only input parameter.
The
Store procedure has input and output parameter.
The Function always returns a value.
The stored procedure is optional. It’s May or may not
return a value.
The Function utilised only SELECT command.
The Store procedure utilised DDL (Data Definition
Language), DML (Data Manipulation Language) command.
DDL- CREATE, ALTER, DROP
DML- SELECT, INSERT, UPDATE, DELETE
You cannot use try catch block in Function.
You can use try catch block in Store procedure.
You cannot use transactions in Function.
You can use transactions in Store procedure.
You cannot call Store procedure inside Function.
You can call Function inside Store procedure.
The Function can be used in Select statement.
The Store procedure can’t use in Select statement.
The Function called using SELECT.
The Store procedure called using EXEC or EXECUTE.
No comments:
Post a Comment