Saturday, July 23, 2016

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.

Example of the stored procedure is given below:

Firstly we create a table with the name emp


Then create stored procedure:
create procedure abc(@id int, @nm varchar(20),@s1 int)
as
insert into emp values(@id, @nm, @s1)
return

After execute the above code we insert data into table by using the following syntax

exec abc 6,'Abi',22000


Output: 



 


Thursday, July 21, 2016

Magic table in SQL Server

There are two types of Magic table in SQL Server:

Inserted
Deleted

Inserting into table (Inserted table):


When we insert anything in base table in database, a table is automatically created by the SQL server, it is called inserted, and this table contains current updated or inserted record. We can access the record of this table via triggers.

Updating Table (inserted or deleted table):


When we delete anything in base table in database, in spite of one, two tables are created one is called INSERTED and another is called DELETED. Deleted table contain current record after the deletion operation and Inserted table contain previous record .We can access via triggers.

Deleting (Deleted Table):



When we deleted anything in base table in Database, a table is created by SQL Server called deleted table, this table contain current updated record after deletion operation. We can access this record via triggers.


                                               Author : Sachin Pathak

Tuesday, July 12, 2016

dot net and Sql interview questions for experienced

After clearing telephonic interview, I was went "India Bulls"  for face to face technical round, here I write some questions which is asked there

Telephonic interview question of India Bulls

Question 1 What is means of abstraction and encapsulation ? (Answer this question as real time scenario).

Question 2 What is difference between  readonly and constant in c#, give an example in real time scenario or say where we need to use these in our project?

Question 3 What is Abstract class?

Question 4 does abstract class have constructor?

Question 5 can we create object of abstract class if yes or no then why?

Question 6 if no then why we define constructor in abstract class?

Question 7 it is necessary to declare abstract class all methods will be abstract ?

Question 8 it is necessary to declare abstract class all methods will be abstract ?

Question 8  Can we declare abstract methods in normal classes ?

Question 9  If yes then why we need of abstract class ?

Question 10  If yes then why we need of abstract class ?

Question 11  The given below snippet is correct or not ?


class  Test
    {
        public abstract void meth1();
        public virtual void meth2();
    }

Question 12  What is difference between abstract class and Interface and give the real time example to using both of them ?

Question 13  What is output of given below snippet and why?


using System;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Test2 obj = new Test2();
            Console.ReadKey();
        }
    }
    class  Test1
    {
        static Test1()
        {
            Console.WriteLine("Test1");
        }
    }
    class  Test2:Test1
    {
        static Test2()
        {
            Console.WriteLine("Test2");
        }
    }
}

Question 14  What is output of given below snippet and why?


using System;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Test2 obj = new Test2();
            Console.ReadKey();
        }
    }
    class  Test1
    {
        public Test1()
        {
            Console.WriteLine("Test1");
        }
    }
    class  Test2:Test1
    {
        public Test2()
        {
            Console.WriteLine("Test2");
        }
    }
}

Question 15  What is static class and real time use of static class ?

Question 16  What is delegate and real time working of delegate ?

Question 17  What id Dispose() and when we use it?

Question 18  What is difference between ViewState and hiddenfield ?

Question 19  What is Session and and what is InProc and OutProc and when we use it and difference between them ?

Question 20  When we use cookie , given an example  when you need to use cookie?

Question 21  When we use cookie , given an example  when you need to use cookie?

Question 22  What is WCF and WebService?

Question 23  Can we return a table from SQL function?

Question 24  What is view in sql?

Question 25  Can we perform insert , update and delete operation using View in SQL?

Question 26  What is trigger , define step by step how trigger executed and when we need to use of triggers in sql?

Question 27  What is magic table in sql?

Question 28  What is temporary table in sql , use of temporary table  and difference between local and global temporary tables?

Question 29  can we call stored procedure inside function in sql?

Question 30  can we call function inside stored procedure in sql?

Question 31  how many no of out parameter declare in stored procedure?

Question 32  Write a query to output look like?

Table is:

Column1 Column2
A 100
B 200
C 300
A 200
B 300

Output is:
 
Column1 Column2 Count
A 300 2
B 500 3
C 300 1

Question 33  Write a query of uncolored area suppose two circle is two tables in sql?

Question 34  Write a query of uncolored area suppose two circle is two tables in sql?

Table is:
Column1
2
3
4
1
5

Output is:

Column 2 Cumulative Sum
2 2
3 5
4 9
1 10
5 15



Question 35  What is difference between DataSet and SqlDataReader and real time use of it and why dataset come after SqlDataReader ?

Question 36  What is difference between var and dynamic keyword in c# ?

Question 37  What is value type and reference type in c# if int is value type then please explain given below snippet 

int a = new int();

where its value is stored (heap or stack and why)?

Question 38 What is enum in c#, when we use it?

Question 39 What is struct in c#?

Question 40 Explain given below snippet?


private void Test()
    {
        try
        {
            //execption occur
        }
        catch {
        //here also execption ,    then what will be happen the exception is handled or not   ?    //because we want to insert some value in sql table how can you handle it
        }
        finally
        {
       
        }
    }

Thursday, July 7, 2016

How to use file upload control in asp.net with update panel

In this article, I am going to explain how to use file upload control inside update panel in asp.net c#. Create a folder with name "Upload" for saving your file at solution explorer.

aspx code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UploadFileInsideUpdatePanel.aspx.cs" Inherits="UploadFileInsideUpdatePanel" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="smain" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="upmain" runat="server">
    <ContentTemplate>
    <fieldset>
    <legend>Upload File Inside Update Panel</legend>
    <asp:FileUpload ID="flupload" runat="server" />
    <asp:Button ID="bthUplaod" runat="server" Text="Save" onclick="bthUplaod_Click" />
    <asp:Label ID="lblmsg" runat="server" ForeColor="Green"></asp:Label>
    </fieldset>
    </ContentTemplate>
    <Triggers>
    <asp:PostBackTrigger ControlID="bthUplaod" />
    </Triggers>
    </asp:UpdatePanel>
    </form>
</body>
</html>

aspx.cs code

using System;
using System.IO;
 
public partial class UploadFileInsideUpdatePanel : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void bthUplaod_Click(object sender, EventArgs e)
    {
        try
        {
            lblmsg.Text = string.Empty;
            if (flupload.HasFile)
            {
                string physicalDirPath = Server.MapPath("~/Upload");
                string filedata = Path.GetFileNameWithoutExtension(flupload.FileName) + Guid.NewGuid() + Path.GetExtension(flupload.FileName);
                string filename = physicalDirPath + "\\" + filedata;
                flupload.SaveAs(filename);
                lblmsg.Text = "Saved Successfully";
            }
        }
        catch (Exception ex)
        {
            lblmsg.Text = ex.Message;
        }
    }
}

Output:




Monday, July 4, 2016

Difference between Asp.Net Web Services and WCF


                 Web service
                         WCF
 It is hosted only in IIS
It is hosted in IIS, WAS(Windows activation service), Windows Service, Self-hosting
WebService attributes are used to define a web service
ServiceContract attributes are used to define a WCF service.
It supports only HTTP, HTTPS protocols.
It support various protocols like HTTP, HTTPS, TCP, Named Pipes etc.
It is slower than WCF
It is faster than web services
Hash Table cannot be serialized
Hash table cab be serialized
It support XML and MTOM message encoding
It support XML, MTOM, Binary message encoding
It does not support multi-threading.
It support multi-threading
It support one-way and request-response service operations.
It supports one-way, request-response and Duplex service operations.
It support XML serializer
It support DataContract serializer