Tuesday, February 19, 2013

Concatenate fields in item template GRID

Grid


Concatenate  fields in item template

Text='<%# string.Concat(DataBinder.Eval(Container.DataItem, "ID"), " ", DataBinder.Eval(Container.DataItem, "InstanceID")," ", DataBinder.Eval(Container.DataItem,"TypeCode") %>'


Monday, February 11, 2013

Linq - Delegates , Anonymous functions




delegate in where condition


An anonymous function is an "inline" statement or expression that can be used wherever a delegate type is expected. You can use it to initialize a named delegate or pass it instead of a named delegate type as a method parameter.

var fu = productMemberResponse.ProductList.Where(delegate(ProductMemberDetails pmd)
                {
                    if (pmd.Type == "SEP")
                        return sepProduction;
                    else if (pmd.Type == "PIM")
                        return pimProduction;
                    else return true;
                }
                ) ;



A lambda expression is an anonymous function that you can use to create delegates or expression tree types. By using lambda expressions, you can write local functions that can be passed as arguments or returned as the value of function calls. Lambda expressions are particularly helpful for writing LINQ query expressions.


(input parameters) => expression

(input parameters) => {statement;}

Func<bool, int> del = x => x ? 10 : 5; 
    new ShoppingCart().Process(del);


Friday, February 1, 2013

Interview Questions On SQL

Update


1) How update works internally ?
----------------------------
--
-- Oops! SQL column swap or SQL column clobber?
--
create table #temp (PK int identity, c1 int, c2 int);

insert into #temp values (1,2);
insert into #temp values (3,2);
insert into #temp values (2,1);
insert into #temp values (5,2);
insert into #temp values (5,3);

select * from #temp order by PK;
--
-- Swap columns c1 and c2 on a
-- row-by-row basis if c1 > c2
--

update #temp
 set c1 = c2, c2 = c1
 where c1 > c2;

--
-- Will column c2 clobber column c1
-- BEFORE column c1 can replace column c2?
-- Do we need a temporary column
-- or variable to correct this?
--
select * from #temp order by PK;
--

drop table #temp;


2) 
-- #1 Table
CREATE TABLE GenderUpdate
(
ID SMALLINT IDENTITY,
Gender CHAR(1)
);

-- #2 Data
INSERT INTO GenderUpdate (Gender) 
VALUES ('M'), ('M'),('M'),('M'),('M'),('M'),('F'),('F'),('F'),('F'),('F'),('F'),('F'),('F'),('F'),('F')

-- #3 To check the data count gender wise
SELECT Gender, COUNT(gender) [COUNT] FROM GenderUpdate GROUP BY gender

-- #4 Final update with case statement
UPDATE GenderUpdate
 SET Gender = CASE WHEN GENDER = 'M' then 'F' ELSE 'M' END

 SELECT Gender, COUNT(gender) [COUNT] FROM GenderUpdate GROUP BY gender