Wednesday, December 26, 2012

Total size of an index or primrary key cannot exceed 900 bytes


When we are making primrary key of a multiple columns , then normally we can face this limit of sql server. Thats fixed and hard limit. You have to simply reduce the size of your columns on which you are creating primrary key .

if you ask why ?  I also dont know why this type of limits are used in MS  SQL SERVER .

Thursday, November 8, 2012

REMOVE DUPLICATE ROWS FROM A TABLE USING SQL

SQL FOR REMOVING DUPLICATE


create table demo(
  id int identity(1,1) not null,
  alpha nvarchar(50)
 
)
insert into demo select 'A'
insert into demo select 'A'
insert into demo select 'A'
insert into demo select 'A'
insert into demo select 'A'


select * from demo

;WITH cte
     AS (SELECT ROW_NUMBER() OVER (PARTITION BY alpha
                                       ORDER BY ( SELECT 0)) RN
         FROM   demo)
DELETE FROM cte
WHERE  RN > 1


select * from demo

update table from another table or same table using inner join


declare @temp table
 (
  Id int identity(1,1) not null,
  alpha nvarchar(50)

 )

 insert @temp  select null
 insert @temp  select null
 insert @temp  select null

 select * from @temp

declare @temp1 table
 (
  Id int identity(1,1) not null,
  alpha nvarchar(50)
 )


 insert @temp1  select 'A'
 insert @temp1  select 'B'
 insert @temp1  select 'C'

 select * from @temp1


 update @temp   set alpha=t1.alpha
 FROM   @temp as t    inner join  @temp1  as t1 ON t.id=t1.id



 select * from @temp

Saturday, October 20, 2012

How to convert c# array into list type of object

hotel[] hotels= new [] { 10, 20, 10, 34, 113 };


 public hotel[] availableHotels ;

availableHotels=

print month name

simple DATENAME function can be used to print month name 

 select DATENAME(month,getdate())


most simple example to understand common table expression in sql

Just declaration of a temporary table with single column 
declare @temp1 table
 (
   id int
 )

insert statement to insert one row in temporary table @temp1

 insert into @temp1 select 1
 common table expression example to recursively increase the column Id. i think this is the most simple example of looping or recursion to print 1 to 10 with out printing each statement individually .... :)








Here is code of common table expression in sql  
;with cte As
   (
     select id from @temp1
     union all
     select id+1 from cte where id<10 br="br">   )
   select * from cte
sql fiddle for this post can be find here sqlfiddle link 

Thursday, October 11, 2012

Select all dates between first day of month and current date without loop


DECLARE @startDate DATETIME=CAST(MONTH(GETDATE()) AS VARCHAR) + '/' + '01/' +  + CAST(YEAR(GETDATE()) AS VARCHAR) -- mm/dd/yyyy
DECLARE @endDate DATETIME= GETDATE() -- mm/dd/yyyy
;WITH Calender AS (
    SELECT @startDate AS CalanderDate
    UNION ALL
    SELECT CalanderDate + 1 FROM Calender
    WHERE CalanderDate + 1 <= @endDate)
SELECT [Date] = CONVERT(VARCHAR(10),CalanderDate,25) FROM CalenderOPTION (MAXRECURSION 0)
DECLARE @startDate DATE=CAST(MONTH(GETDATE()) AS VARCHAR) + '/' + '01/' +  + CAST(YEAR(GETDATE()) AS VARCHAR)  -- mm/dd/yyyy
DECLARE @endDate DATE=GETDATE() -- mm/dd/yyyy
SELECT [Date] = DATEADD(Day,Number,@startDate) FROM  master..spt_values WHERE Type='P'
AND DATEADD(day,Number,@startDate) <= @endDate
declare @temp table (ddate datetime);
insert @tempselect DATEDIFF(d,0,GetDate()-Number)
from master..spt_valueswhere type='p' and number < DatePart(d,Getdate())
order by 1;

Thursday, October 4, 2012

simple example of pivot in sql

declare @temp table (


id int identity(1,1),

deptname nvarchar(500),

type nvarchar(1),

value int

)



insert into @temp

select 'payroll','a',20

union all

select 'payroll','b',20

union all

select 'payroll','b',10

union all

select 'sales','a',20

union all

select 'sales','b',20

union all

select 'sales','b',10







select * from @temp



select deptname,a,b,c from

(select SUM(value) as value,deptname,type from @temp group by type,deptname) p

pivot (SUM(value) FOR type IN (a,b,c)) AS pvt

Sunday, August 19, 2012

Get Checkbox values comma separated using jquery

<div id="c_b">
<div class="checktextrow">
                                    <div class="peroperty_checks"><input type="checkbox" name="swimmingpool" id="swimmingpool" value="1"></div>
                                    <div class="peroperty_text">Swimming Pool</div>
                                    </div>
                                      <div class="checktextrow">
                                    <div class="peroperty_checks"><input type="checkbox" name="fitnesscenter" id="fitnesscenter" value="2"></div>
                                    <div class="peroperty_text">fitness center</div>
                                    </div>
                                      <div class="checktextrow">
                                    <div class="peroperty_checks"><input type="checkbox" name="restaurant" id="restaurant" value="3"></div>
                                    <div class="peroperty_text">restaurant</div>
                                    </div>
                                      <div class="checktextrow">
                                    <div class="peroperty_checks"><input type="checkbox" name="childrenactivities" id="childrenactivities" value="4"></div>
                                    <div class="peroperty_text">children’s activities</div>
                                    </div>
                                    
                                     <div class="checktextrow">
                                    <div class="peroperty_checks"><input type="checkbox" name="complimentarybreakfast " id="complimentarybreakfast " value="5"></div>
                                    <div class="peroperty_text">complimentary breakfast </div>
                                    </div>
                                    
                                     <div class="checktextrow">
                                    <div class="peroperty_checks"><input type="checkbox" name="meetingfacilities" id="meetingfacilities" value="6"></div>
                                    <div class="peroperty_text">meeting facilities</div>
                                    </div>
                                    
                                    
                                    <div class="checktextrow">
                                    <div class="peroperty_checks"><input type="checkbox" name="petsallowed " id="petsallowed " value="7"></div>
                                    <div class="peroperty_text">pets allowed </div>
                                    </div>
                                    
                                     <div class="checktextrow">
                                    <div class="peroperty_checks"><input type="checkbox" name="wheelchair" id="wheelchair" value="8"></div>
                                    <div class="peroperty_text">wheelchair accessible</div>
                                    </div>
                                    
                                    <div class="checktextrow">
                                    <div class="peroperty_checks"><input type="checkbox" name="kitchen" id="kitchen" value="9"></div>
                                    <div class="peroperty_text">kitchen/kitchenette</div>
                                    </div>
</div>

 <textarea id="t"></textarea>



Here is jquery code for access all checkbox using jquery and set the checkboxes values in textarea.



 function updateTextArea() {
         
         var allVals = [];
         $('#c_b :checked').each(function() {
           allVals.push($(this).val());
         });
         $('#t').val(allVals)
      }
     $(function() {
       $('#c_b input').click(updateTextArea);
         updateTextArea();
     });



complete  working example can be check here 



Tuesday, August 14, 2012

replace html of a div using jquery

replace html of a div using jquery 
this is  simple . just use .html() method of jquery to set new html for a div .

$("#divID").html("new text");

Tuesday, August 7, 2012

why only 24 hours ?

i m feelin these days that in a day we have "only " 24 hours ?

does method signature include return type in C sharp (c#)

does method signature include return type in C sharp (c#)

I would say  BIG  NO


I read a lot of blogs and finally i have decieded to test by self and i just make some simple code

protected int sum(int a, int b)
    {
        return a + b;
    }

    protected float sum(int a, int b)
    {
        return a + b;
    }


when i run this its throws error

already defines a member called 'sum' with the same parameter types

but if i change the parameter type then its runs OK

so final result is method signature not  include return type. and a method can be not overloaded just by changing its return type .



what is the difference between wcf service and web service?

WCF is a programming model and API. "WCF Service" implies an app that is built using that programming model and API.
"Web Service" is an app that exposes an HTTP (REST (XML or JSON), SOAP or otherwise) interface.
You can build a Web service using WCF, but you can also build a Web service using other APIs or "stacks". Like PHP or Java, for example.
With WCF you can build web services but you can also build services that are not, "Webbish". For example you can build a service that accepts incoming binary requests over only a local pipe interface. It is still a service, but it is not a "web service" because it is not using web protocols (generally HTTP and XML).

reference

Friday, July 27, 2012

Get checkboxlist selecte items in a string with comma seprated

this is code to get  selected items in checkbox list as a string separated with comma or any delimeter you want to use like |(Pipe singn)

var selectedValues = (from item in chbBroadType.Items.Cast() where item.Selected select item.Value).ToArray();
var selectedValuesJoined = string.Join(",", selectedValues);

Get count of checkboxlist selected items

this is single line of code that can be used to get the number of items selected in checkboxlist in asp.net with c#

int count= ChbProperty.Items.Cast<ListItem>().Count(li => li.Selected);

Sunday, July 22, 2012

parthavi new photos (cool without hair )

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

parthavi atri

How to get java script variable value on server side

The answer is Hidden field or any input control.

You just need to take hidden field and set the value of  java script variable on hidden filed .like below

var javascriptvariable='some value'; 
$('#hiddenfield').val(javascriptvariable);
 
 
Now on server side you can get the hidden field which is 
actually java script variable  value 
 
String hdnvalue=hiddenfield.value;
 
I have used Jquery val function to set the value .
 You can use val function of jquery  in
two ways to get the value just use the 
 $('#hiddenfield').val(
 
and for setting the value you need to pass 
the value as argument in val function 
like this 
 
 
 $('#hiddenfield').val('31october') 
 alert($('#hiddenfield').val() );
 
 
you can check live demo here .
 
http://jsfiddle.net/VaKfP/255/
 
 
 I love http://jsfiddle.net/  for jquery code sharing.  
 
 
Thanks   

Friday, July 6, 2012

get the dropdown value and text using jquery

we have a drop down an ID, Name Pair.
Example

Rahul has ID of 1
Chand has ID of 2
Parthavi has ID of 3
When I do the followng:
alert($('#Crd').val());
and we select Rahul , we get 1

but in case we want selected text in jquery for a dropdown
then

$('#dropdownId option:selected').text();

Interview Question you might face ?

Reflection
Serialization
Stateless and statfull application
web service
jquery
json
Static Class
Static Class Inheritance
Abstract Data Type
DataAdapter and DataReader
Can we use session in Ajax

Interview Questions with answer

hi dear ,
actually these days i m bg with interviews so i m refreshing c# or asp.net concepts,so i want to share with u also these so if u go for the interview next time jst go through hope they will help u ..........

Q.1-what is interface and why its used ?

Ans.1-An interface looks like a class, but has no implementation. The only thing it contains are definitions of events, indexers, methods and/or properties. The reason interfaces only provide definitions is because they are inherited by classes and structs, which must provide an implementation for each interface member defined.
So, what are interfaces good for if they don't implement functionality? They're great for putting together plug-n-play like architectures where components can be interchanged at will. Since all interchangeable components implement the same interface, they can be used without any extra programming. The interface forces each component to expose specific public members that will be used in a certain way.
Because interfaces must be implemented by derived classes and structs, they define a contract. For instance, if class foo implements the IDisposable interface, it is making a statement that it guarantees it has the Dispose() method, which is the only member of the IDisposable interface. Any code that wishes to use class foo may check to see if class foo implementsIDisposable. When the answer is true, then the code knows that it can call foo.Dispose(). Any difference between the method signature in the interface and the method signature in the implementing class or struct will cause a compiler error. Additionally, a class or struct that inherits an interface must include all interface members; You will receive a compiler error if you don't implement all interface members.
You can implement an interface and use it in a class. Interfaces may also be inherited by other interface. Any class or struct that inherits aninterface must also implement all members in the entire interface inheritance chain.
Interfaces consist of methods, properties, events, indexers, or any combination of those four member types. An interface cannot contain constants, fields, operators, instance constructors, destructors, or types. It cannot contain static members. Interfaces members are automatically public, and they cannot include any access modifiers.

When a class or struct implements an interface, the class or struct provides an implementation for all of the members defined by the interface. The interface itself provides no functionality that a class or struct can inherit in the way that base class functionality can be inherited. However, if a base class implements an interface, the derived class inherits that implementation. The derived class is said to implement the interface implicitly.

Classes and structs implement interfaces in a manner similar to how classes inherit a base class or struct, with two exceptions:

A class or struct can implement more than one interface.

When a class or struct implements an interface, it receives only the method names and signatures, because the interface itself contains no implementations,



Q.2-difference between abstract class and interface ?

Ans.2-

Q.3-What is an Abstract Class?


Ans.3-An abstract class is a special kind of class that cannot be instantiated. So the question is why we need a class that cannot be instantiated? An abstract class is only to be sub-classed (inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards.

Q.4-What is an Interface?


ans.4-An interface is not a class. It is an entity that is defined by the word Interface. An interface has no implementation; it only has the signature or in other words, just the definition of the methods without the body. As one of the similarities to Abstract class, it is a contract that is used to define hierarchies for all subclasses or it defines specific set of methods and their arguments. The main difference between them is that a class can implement more than one interface but can only inherit from one abstract class. Since C# doesn�t support multiple inheritance, interfaces are used to implement multiple inheritance.



Q.5-what is abstract class ?



Ans.5-Abstract classes are closely related to interfaces. They are classes that cannot be instantiated, and are frequently either partially implemented, or not at all implemented. One key difference between abstract classes and interfaces is that a class may implement an unlimited number of interfaces, but may inherit from only one abstract (or any other kind of) class. A class that is derived from an abstract class may still implement interfaces. Abstract classes are useful when creating components because they allow you specify an invariant level of functionality in some methods, but leave the implementation of other methods until a specific implementation of that class is needed. They also version well, because if additional functionality is needed in derived classes, it can be added to the base class without breaking code.

An abstract class is denoted in Visual Basic by the keyword MustInherit. In C#, the abstract modifier is used. Any methods that are meant to be invariant may be coded into the base class, but any methods that are to be implemented are marked in Visual Basic with the MustOverride modifier. In C#, the methods are marked abstract

When implementing an abstract class, you must implement each abstract (MustOverride) method in that class, and each implemented method must receive the same number and type of arguments, and have the same return value, as the method specified in the abstract class.



Q.6-Difference between class and structure ?

Ans.6-classes are refrence types where the structures are the value types Since classes are reference type, a class variable can be assigned null.But we cannot assign null to a struct variable, since structs are value type.
when u insitate a class it will be allocated on heap where in the case of structure its get created on stack.
when passing a class to a method it will be passed by refrence but in case we pass struct as parameter it will be passed by value.
you cannot have instance fileds intilizaries in structs but class can have.
structure does not support inheritance where class supports the inheritance.
classes are used for large and complex datasets where the structs are simple to use.

Q.7-difference between vs 2005 and vs 2008 ?

Ans.7-


Q.8-what is web service and how to used ?

Ans.8-  Web service" as "a software system designed to support interoperable machine-to-machine interaction over a network"

Q.9-difference between overloading and overriding ?

Ans.9-
 OVERLOADING :
Overloading is when you have multiple methods in the same scope, with the same name but different signatures.
Overloading is the example of compile-time polymorphism.
//Overloading
public class test{
    public void getStuff(int id)
    {}
    public void getStuff(string name)
    {}
}
OVERRIDING :
Overriding is a principle that allows you to change the functionality of a method in a child class


//Overriding
public class test{
        public virtual getStuff(int id)
        {
            //Get stuff default location
        }
}
public class test2 : test{
        public override getStuff(int id)
        {
            //base.getStuff(id);
            //or - Get stuff new location
        }
}
  Overriding is the example of run-time polymorphism




Q.10-if we have master page or contain page, and a button on contain page is clicked ,then which load method call first ?
Ans.10-
Q.11-What is marshelling ?what is the use of marsheling in c# ?
Ans.11-
Q.12-What is deligates ? How many types of deligates ?
Ans.12-
Q.13-Example of static and dynamic ploymorphism ?
Ans.13-
Q.14-Which event is occured when a grid view button is clicked ?
Ans.14-
Q15.Difference between ds.copy () or ds.clone () ?
Ans.15-The Clone method of the DataSet class copies only the schema of a DataSet object. It returns a new DataSet object that has the same schema as the existing DataSet object, including all DataTable schemas, relations, and constraints. It does not copy any data from the existing DataSet object into the new DataSet.

The Copy method of the DataSet class copies both the structure and data of a DataSet object. It returns a new DataSet object having the same structure (including all DataTable schemas, relations, and constraints) and data as the existing DataSet object.
Q.16 What is static constructor ?if i make 4 objects of any class then how many times of static constructor will be called ?

Ans.16--
Q.17-jquery ? how to use ? $ why used ?
Ans.17-
Q.18-what is clr ?
Ans.18-
Q.19 what do you understand by .net assembly ?
Ans.19-
Q.20-partial class ?
Ans.20-

Q.21-What is reflection ?
Ans.21-
Q.22-server.transfer and response.redirect ?
Ans.21-
Q.22-how u achieve abstraction in a project ?
Ans.22-

Q.23-managed code and unmanaged code ?

Ans.23-Here is some other complimentary explication about Managed code:
  • Code that is executed by the CLR.
  • Code that targets the common language runtime, the foundation of the .NET Framework, is known as managed code.
  • Managed code supplies the metadata necessary for the CLR to provide services such as memory management, cross-language integration, code access security, and automatic lifetime control of objects. All code based on IL executes as managed code.
  • Code that executes under the CLI execution environment.

Managed code is not compiled to machine code but to an intermediate language which is interpreted and executed by some service on a machine and is therefore operating within a (hopefully!) secure framework which handles dangerous things like memory and threads for you. In modern usage this frequently means .NET but does not have to.
Unmanaged code is compiled to machine code and therefore executed by the OS directly. It therefore has the ability to do damaging/powerful things Managed code does not. This is how everything used to work, so typically it's associated with old stuff like .dlls



Q.24-native code ?
Ans.24-

Q.25-sealed class ?

Ans.25-Sealed class is used to define the inheritance level of a class.

The sealed modifier is used to prevent derivation from a class. An error occurs if a sealed class is specified as the base class of another class.

Some points to remember:

1. A class, which restricts inheritance for security reason is declared, sealed class.
2. Sealed class is the last class in the hierarchy.
3. Sealed class can be a derived class but can't be a base class.
4. A sealed class cannot also be an abstract class. Because abstract class has to provide functionality and here we are restricting it to inherit.

Q.26-How to use javascript from code behind in asp.net ?
ans.26-
Page.ClientScript.RegisterStartupScript


(this.GetType(), "alert", "alertMe();", true);

Q.27-differenc between string and stringbuilder ?

ans 27.-
"The String object is immutable. Every time you use one of the methods in the System.String class, you create a new string object in memory, which requires a new allocation of space for that new object. In situations where you need to perform repeated modifications to a string, the overhead associated with creating a new String object can be costly. The System.Text.StringBuilder class can be used when you want to modify a string without creating a new object. For example, using the StringBuilder class can boost performance when concatenating many strings together in a loop."

Q.28-What is immutable ?

ans.28-an immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created.
example :-
String s = "ABC";
s.toLowerCase();

The method toLowerCase() will not change the data "ABC" that s contains. Instead, a new String object is instantiated and given the data "abc" during its construction


Q.29-how to get client side id of a textbox in javascript function in asp.net ?
ans.29-var txtBox = document.getElementbyId("<%=txtBoxSnrInsp.ClientID %>");

Q.30-What are the different parameter modifiers available in C#?
Ans.30-Parameter modifiers in C# are entities that controls the behaviour of the arguments passed in a method. Following are the different parameter modifiers in C#:
1) None - if there is NO parameter modifier with an argument, it is passed by value, where the method recieves a copy of the original data.
2) out - argument is passed by reference. The argument marked with "out" modifier needs to be assigned a value within this function, otherwise a compiler error is returned.

public void multiply(int a, int b, out int prod)
{
prod = a * b;
}

Here, note that prod is assigned a value. If not done so, then a compile time error is returned.
3) params- This modifier gives the permission to set a variable number of identical datatype arguments.
Note that a method may have only one "params" modifier. The params modifier needs to be in the last argument.

C# Example
static int totalruns(params int[] runs)
{
int score = 0;
for(int x=0; x
&nsbp;score+=runs[x];
return score;
}

Further, from the calling function, we may pass the scores of each batsman as below...

score = totalruns(12,36,0,5,83,25,26);

4) ref - The argument is given a value by the caller, where data is passed by reference. This value may optionally be reset in the called method. Note that even if NO value is set in the called method for the ref attribute, no compiler error is raised.
Q.31-What are different validation controls available in asp.net tool box ?

Source is google suggested results from different tutorial or websites....
Rahul Kumar Sharma