Monday 29 June 2015

Object reference not set to an instance of object?

If this type of error you are getting anywhere in .net application means some parameter or object passing null values to a method.
Check the value against null. Somewhere null values/values  are/is passing.

Which class can not be inherited from object class?

None!. All clases are inherited from system.object clas. If class not inherited from system.object class then why all the class have .ToString(),GetHashCode and other object inherited functions.
I have read many blogs and answers some are saying that sealed and abstract class can not be inherited from system.object class. But it is wrong.

System.Object class is the parent class of all the classes. By the definition of class sealed and abstract class , definitions saying that you can inherite the class or you cann’t make derived from these class . It is not saying it s not inherited from system.Object class. So we definitely say that all the class is inhetited from system.Object class.

Can we call static method from abstract class in c#?

Yes. We can call static method from abstract class. Static method does not required instance of class. Object of abstract class can’t be created but to call static object  is not required. So we can call static method with abstract class name i.e abstractclass.methodname();

Example :-

public abstract class Abstractest
    {
        public static string Test()
        {
           return  "Static method in abstract class";
        }
    }
static void Main(string[] args)
        {
            Abstractest.Test();
            Console.ReadLine();
        }

What is mean by Partial class?

It is new features in .Net 2.0; partial classes mean that class definition can be split into multiple physical files. Logically,......
                                                                                                                           Read More

What is mean by Partial class?

It is new features in .Net 2.0; partial classes mean that class definition can be split into multiple physical files. Logically, partial classes do not make any difference to the compiler. The compiler intelligently combines the definitions together into a single class at compile-time

Customer1.cs:-
partial class Customer
    {
        int age;
        public int Age
        {
            get { return age; }
            set { age = value; }
        }
        public void GetDeyails(int id)
        {
            GetEmpName(id);
        }
        partial  void GetEmpName(int id)
        {
            Console.Write("Employee1");
        }
    }

customer1.cs
partial class Customer
    {
        string name ;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
         partial void GetEmpName(int id);
    }

static void Main(string[] args)
{
 Customer cust = new Customer();
            cust.Name = "SKM";
            cust.Age = 123;
            //string res;
            cust.GetDeyails(1);
}

Thursday 18 June 2015

We all know in Try-catch-finally block finally is called every time whether exception came or not, but in which condition or scenario finally block will not called?

As we know that finally block will called every time whether exception occurred or not, but in some scenario finally will not called.

Finally block will not called in the following scenario:-
1.) System.ExecutionEnginException
2.) System.StackOverFlowException
3.) Page state is changed inside try block

Where the class variable and globle variable get stored after the class object created?

When object of class created then
1.) Class level variables stored in Heap.
2.) Value type variables stored in stack.

Difference between string.Empty and “ ”?


String.Empty  will not create any object of String while “ “ will create a new  object in the memory.
.Length == 0 is the fastest option , but .Empty makes slightly cleaner code.
String.Empty is read-only field while “ “ is compile time constant.

Wednesday 10 June 2015

CHARINDEX function in Sql Server2008?

CHARINDEX function is used to get starting position of specified expression in a string.

Syntax of CHARINDEX function :-

CHARINDEX(expression1,(expression2[,Start_Location])

expression1 is a sequence of character to be found in expression2. It is of short character datatype.

expression2  is a string in which expression1 to be search. It is of character string datatype.

Start_Location is position to start searching expression1 in expression2 .It is an optional field. If you will provide anything then it start search from position 0.

Examples:-

Example1:-

DECLARE @cust varchar(300),@pos int
set @cust='a,b,c,d'
Select CHARINDEX(',',@cust,1)

Output:-
2

Example2:-

Select CHARINDEX('am','Example-syntax-Example',1)

Output:-
3

Friday 5 June 2015

Table A have 5 rows and Table B have 7 rows. How many rows does “Select * from A, B” return?

It will return 35 rows.

Table A have 5 columns and Table B have 7 columns. How many columns does “Select * from A, B” return?

It will return 12 columns.

How to get all tables name from database in SQLServer 2008?

To get all tables names from DataBase:-

select * from information_schema.tables
Select * from SYS.TABLES

What is the purpose of HTTP, SOAP in web service?

Client application method call goes to proxy, proxy covert method call to xml format that is soap message.
SOAP message will reach web server via HTTP protocol.
Webserver create the object of web service and execute the method.
The result in the form of soap format is given to client back over HTTP.

Why SOAP?

SOAP is important for application development to allow Internet communication between programs.
Instead of SOAP we are also using RPC (Remote procedure call) for object DCOM, COM etc.. But HTTP was not designed for this. RPC represents compatibility and security problems; firewall and proxy server is blocking this kind of traffic.

SOAP is a better way to communicate between applications over HTTP, because HTTP is supported by all internet browsers and servers.

SOAP is platform independent and language independent means it can communicate between applications running on different operating system, with different technology and programming languages.

What is SOAP?

SOAP is a simple xml based protocol to exchange the information over HTTP.
SOAP stands for Simple Object Access Protocol

  • It is a communication protocol.
  • It communicates between applications.
  • It is a format for sending message.
  • It communicates via internet.
  • It is platform independent.
  • It is language independent.
  • It is based on xml.
  • It is simple and extensible.
  • It is not blocked by firewall.

XML Vs XAML OR what is difference between XMLand XAML?

XML stands for Extensible Markup Language.

XAML stands for Extensible Application Markup Language.

XAML is based on XML and it uses XML for its markup. Every XAML is valid XML document but Every XML is not valid XAML.


XML finds it use in primarily in web application while XAML is used to design controls of windows application as well as web application.

Why c# codes are converted to IL and why C++ codes are converted to machine code not IL?


C++ code after compilation is converted into Machine code because it is platform dependent. C++ is designed and executes it on its own compiler and which is not to design and execute code written on another language.

C# is a .net language and it is a platform independent language. It needs common environment and common format to execute code. .net supports 44 types of languages.  C# (Microsoft) converts all the language code into common code is called as Microsoft Intermediate Language(MSIL). This is executed and loaded by the CLR at time of running.IL code in all other OS with help of CLR, which will integrate in .Net Framework. 

call or consume web service (apsx) using Jquery Ajax with example in asp.net.

In this I will explain how to call or consume web service (apsx) using Jquery Ajax with example in asp.net.

Create one web project . In this add new  web service(aspx) file using right click on solution explorer.
Configuration web service to handle JQuery AJAX :-

By default web service do not accept request from client side using JQuery AJAX. To allow web service   handle JQuery AJAX , uncomment the following line

// [System.Web.Script.Services.ScriptService]

The following web service consists GetDetails we method, which accepts name and designation parameter .

C#:-

using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
 [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
    public Service () {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }

    [WebMethod]
    public string GetDetails(string Name,string Designation) {
        return string.Format("Name :{0}{1} Designation :{2}{1}  Date :{3}", Name, Environment.NewLine, Designation, DateTime.Now.ToString());
    }
   
}

Consuming Web Service (ASMX) using JQuery AJAX in asp.net

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript" language="javascript">
    $(function (){
      $("[id*=btnSubmit]").click(function () {
       var name=$.trim($("[id*=txtName]").val());
       var desgn=$.trim($("[id*=txtDesgn]").val());
       $.ajax({
          type:"POST",
          url :"Service.asmx/GetDetails",
          data : "{Name: '"+name+"', Designation:'"+desgn+"'}",
          contentType : "application/json; charset=utf-8",
          dataType :"JSON",
          success:function(r){
            alert(r.d);
          },
          error:function(r){
            alert(r.responseText);
          },
          failure:function(r){
            alert(r.responseText);
          }
       });
       return false;
      });
    });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>: <asp:TextBox ID="txtName"
        runat="server"></asp:TextBox>
   
    <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>: <asp:TextBox ID="txtDesgn" runat="server"></asp:TextBox>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
    </div>
    </form>
</body>
</html>

ScreenShot :


Tuesday 2 June 2015

Cursor in Sql Server .

Cursor is a database object to retrieve data from result set row by row or one row at a time. Cursor is used when we want one by one row values and insert into another table one by one or update the table values one by one.

Create table article(art_acode varchar(5),art_jcode int,jobchapterid int);

insert some values in this table.

sql query for cursor:- 

DECLARE @name varchar(50)
DECLARE @Fname varchar(50)
DECLARE @Lname varchar(50)
DECLARE   @temp Table(name varchar(50),fname varchar(50),lname varchar(50))
DECLARE Emp_Cur CURSOR
STATIC for
Select Art_acode,Art_Jcode,JobChapterId from article where art_jcode=1876
open Emp_Cur
if @@CURSOR_ROWS>0
begin
FETCH NEXT FROM Emp_Cur into @name,@Fname,@Lname
While @@FETCH_STATUS =0
Begin
--print @name+' '+@Fname+' '+@Lname
insert into @temp(name,fname,lname)
values(@name,@Fname,@Lname)
FETCH NEXT FROM Emp_Cur into @name,@Fname,@Lname
end
end
close Emp_Cur
DEALLOCATE Emp_Cur


Select * from @temp

Difference between ref and out parameters?

Here we discus ref and out parameters in c#. We can use these parameters in different ways.

Ref Parameter:-
It is used as a call by reference value in c#. When its value of parameter is changed in the method, it gets reflected in the calling method.

Out parameter:-
It is used like a ref parameter, but argument can be passed without any value assigning to it. Sometime we do not want to give an initial value to parameter; in this case we use out keyword. The declaration of out keyword is same as ref keyword.

Important facts about ref and out keywords:-

We cannot use ref and out keyword in method overloading simultaneously. Ref and out keyword treated as same datatype at compile time but differently at run-time. Hence method with single parameter cannot be overloaded when one method take ref parameter and another method take out parameter.