Wednesday, December 16, 2009

Forbes India : Person Of The Year

Forbes India : Person Of The Year
Who is your Person of the Year ?

This is our long-list for our Forbes India Person of the Year issue. Who is your favourite?
The person who gets the most votes will be the Forbes India Readers' Choice winner.
Vote here, and you could win prizes.
If your choice agrees with ours (wait for our issue that hits the stands on the 18th December to see who it is) you could win :
  • A Forbes India Tie & Cuff Links set
  • A Reebok Duffle Bag
  • A Forbes India Coffee Mug
  • A Forbes India Umbrella
If there are more than one correct entries, the winners will be decided by a draw of lots. There will be up to 25 prizes.
And everyone who voted for the Readers' Choice winner could win prizes too.
Once more, winners will be selected by a draw of lots from the winning entries. There will be up to 25 prizes.
You can vote for only one person.

તું અહીંયા રમવા આવ – ત્રિભુવન વ્યાસ

તું અહીંયા રમવા આવ – ત્રિભુવન વ્યાસ
તું અહીંયા રમવા આવ મજાની ખિસકોલી,
તું દોડ તને દઉં દાવ મજાની ખિસકોલી.
તું કેવી હ્સે ને રમે મજાની ખિસકોલી,
તારા કૂદકા તો બહુ ગમે મજાની ખિસકોલી.
તું જ્યારે ખીલખીલ ગાય મજાની ખિસકોલી,
તારી પૂંછડી ઉંચી થાય મજાની ખિસકોલી.
તું ઝાડે ઝાડે ચડે મજાની ખિસકોલી,
કહે કેવી મજા ત્યાં પડે મજાની ખિસકોલી.
બહુ ચંચળ તારી જાત મજાની ખિસકોલી,
તું ઉંદરભાઈની નાત મજાની ખિસકોલી.
- ત્રિભુવન વ્યાસ

Pranav Mistry: Magical Man behind the ‘SixthSense’ technology

Pranav Mistry: Magical Man behind the ‘SixthSense’ technology
At TEDIndia, Pranav Mistry demos several tools that help the physical world interact with the world of data — including a deep look at his SixthSense device and a new, paradigm-shifting paper "laptop".
In an onstage Q&A, Mistry says he’ll open-source the software behind SixthSense, to open its possibilities to all.

Watch the video – click here

About the Genius
Pranav Mistry is a PhD student in the Fluid Interfaces Group at MIT’s Media Lab. Before his studies at MIT, he worked with Microsoft as a UX researcher; he’s a graduate of IIT. Mistry is passionate about integrating the digital informational experience with our real-world interactions.
Some previous projects from Mistry’s work at MIT includes intelligent sticky notes, Quickies, that can be searched and can send reminders; a pen that draws in 3D; and TaPuMa, a tangible public map that can act as Google of physical world. His research interests also include Gestural and Tangible Interaction, Ubiquitous Computing, AI, Machine Vision, Collective Intelligence and Robotics.

to know more about him : click here

Sql Server 2008 Feature – Part1

Sql Server 2008 Feature – Part1
Sql Server 2008 Key Features:
 
1) Initializing variable when you declare
declare @val as int =0
declare @currentdate as datetime = getdate
()
print @val
print @currentdate


2) Compound assignment operators
–operator like +=,-=,/=,*/,%=
declare @val as int = 0
set @val += 10
;
print @val

3) Add multiple row in single Insert Statement

CREATE TABLE Employee
(
EmpId int
,
EmpCode varchar(50
),
EmpName varchar(50
)
);

INSERT INTO Employee(EmpId, EmpCode,EmpName
)
VALUES
(1, 'emp1','emp1'
),
(
2, 'emp1','emp1'
),
(
3, 'emp1','emp1'
);

select * from Employee
4) New Data Types

 
 
Data Type
Data Type Use
Date
The Date property returns a Date data type.
Time
Returns values for any valid time of day between 00:00:00 and 23:59:59:9999999. It has a length of at least 8 positions and contains the time in hours,minutes, seconds and fractional seconds.
DateTime2
DateTime2 is an extension of the existing DATETIME type. It has a large date range and large default fractional precision. It has a length of at least 19 positions.
DateTimeOffSet
Returns values for year, month, day, valid time of day between 00:00:00 and 23:59:59:9999999 and offset, in hours, from UTC. It has a length of at least 25 positions.
Hierarchyid
The HierarchyId property is used to identify a position in a hierarchy.
Geography
The SQL Server geography data type stores ellipsoidal (round-earth) data, such as GPS latitude and longitude coordinates
Geometry
The Geometry property contains spatial data that represents information about the physical location and shape of geometric objects.
HierarchyId Data Type
   1: --Create Table Employee

   2: CREATE TABLE Employee

   3: (

   4: EmpId int,

   5: EmpBossId HIERARCHYID,

   6: --GetLevel --> returns the level of the current node in the hierarchy

   7: EmpLevel as EmpBossId.GetLevel() PERSISTED,

   8: EmpCode varchar(50),

   9: EmpName varchar(50)

  10: );

  11: Go

  12: -- Create Insert Store Procedure

  13: Alter PROCEDURE Employee_isp

  14:     @empid int,

  15:     @empbossid int,

  16:     @empcode varchar(50),

  17:     @empname varchar(50)

  18: AS

  19: BEGIN

  20: declare @hid HIERARCHYID,@empboss_hid HIERARCHYID,@last_hid HIERARCHYID

  21:  

  22: if @empbossid = 0 

  23: begin

  24:     set @hid = HIERARCHYID::GetRoot();

  25: end 

  26: else 

  27: begin

  28:   

  29:   SET @empboss_hid = (SELECT EmpBossId FROM Employee  WHERE empid = @empbossid);

  30:   SET @last_hid = (SELECT MAX(EmpBossId) FROM Employee WHERE EmpBossId.GetAncestor(1)= @empboss_hid);

  31:   SET @hid = @empboss_hid.GetDescendant(@last_hid, NULL);

  32: end

  33: INSERT INTO Employee(empid, EmpBossId, EmpCode, EmpName)

  34:             VALUES(@empid, @hid, @empcode, @empname);

  35: END

  36: GO

  37: --insert data

  38: --                     A1

  39: --                AL1           AR1

  40: --           AL1L     AL1R  AR1L   AR1R  

  41: --

  42: --

  43: EXEC Employee_isp @empid =  1, @empbossid = 0, @empcode = 'A1' ,@empname = 'A1';

  44: EXEC Employee_isp @empid =  2, @empbossid = 1, @empcode = 'AL1' ,@empname = 'AL1';

  45: EXEC Employee_isp @empid =  3, @empbossid = 1, @empcode = 'AR1' ,@empname = 'AR1';

  46: EXEC Employee_isp @empid =  4, @empbossid = 2, @empcode = 'AL1L' ,@empname = 'AL1L';

  47: EXEC Employee_isp @empid =  5, @empbossid = 2, @empcode = 'AL1R' ,@empname = 'AL1R';

  48: EXEC Employee_isp @empid =  6, @empbossid = 3, @empcode = 'AR1L' ,@empname = 'AR1L';

  49: EXEC Employee_isp @empid =  7, @empbossid = 3, @empcode = 'AR1R' ,@empname = 'AR1R';

Inserted Data Into Table 
HIERARCHYID 
Different Selection Criteria :
1) Find Employee As Per their Level means Grade 
   select * from Employee where Emplevel = 2
2) Get Child Node 
   SELECT Child.empid, Child.empname FROM Employee AS Parent JOIN Employee AS Child
ON Parent.empid = 2 AND child.empbossid.IsDescendantOf(Parent.empbossid) = 1;
3) Get Parent Node
SELECT parent.empid, parent.empname
FROM Employee AS Parent JOIN Employee AS Child
ON child.empid = 4 AND child.empbossid.IsDescendantOf(Parent.empbossid) = 1;
more on HierarchyId Data Types refer:
http://amitpatriwala.wordpress.com/2009/10/23/hierarchyid-data-type/
5) Introduced New Functions
Function Name
Function Use
SYSDATETIME
Returns current date and time as DateTime2 value.
SYSUTCDATETIME
Returns current date and time in UTC as DateTime2 value
SYSDATETIMEOFFSET
Returns current date and time along with the system time zone as a DATETIMEOFFSET value
SWITCHOFFSET
Adjusts an input DATETIMEOFFSET value to a specified time zone, while preserving the UTC value. For example, the following code adjusts the current system datetimeoffset value to time zone GMT +05:00:
SELECT SWITCHOFFSET(SYSDATETIMEOFFSET(), ‘-05:00′);
TODATETIMEOFFSET
sets the time zone offset of an input date and time value
6) Support Large User Define Types [UDT]
Sql Server 2008 supports large UDT,large UDTs can now reach up to 2 GB in size.
 
Reference Sites: 
http://technet.microsoft.com/en-us/library/cc721270.aspx

Friday, November 27, 2009

Failed to load viewstate Typical problem, with an obvious solution.

Failed to load viewstate Typical problem, with an obvious solution.
Understanding viewstate is fundamental in asp.net, especially if you had run into :

Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

The only way to resolve is a proper understanding of viewstate.

http://geekswithblogs.net/FrostRed/archive/2007/02/17/106547.aspx is a interesting post on viewstate that i happen to read today, pointed out to me by someone who ran into a viewstate problem about the control tree not matching and was clearly afraid of adding controls dynamically after reading some facts presented in that article. Who wouldn't :-)

While the post gives us a very good understanding of viewstate and how it can fail, so i encourage you to read it first, might seem lengthy but I assure you, it's quite interesting. However, when you're done, follow my rant here, since I feel it's important to know, that, the failure can only happen when either done deliberately as per the sample code in the post i linked to above or to *not* understanding viewstate and how it works.


So how can we easily avoid these failures ? Let's look at his first code example, and build onto that :

protected void Page_Init(object sender, EventArgs e)
{
if (!IsPostBack)
{
Button btnClickMe = new Button();
form1.Controls.Add(btnClickMe);
btnClickMe.Text = "Click me";
}
else
{
Label label = new Label();
form1.Controls.Add(label);
}
}

As you can note above, this is problematic, since the control into which viewstate is restored is matched by control index, so when the index changes, as is clear in the above code, because if btnClickMe was loaded in for example index [0], now upon postback, after the page has been recreated and rebuilt, the Label "label" is loaded in index [0] instead and takes the place of the button. So this means viewstate that was meant for the button is loaded into the label instead, and the output in the screen after clicking the button is "click me" which was clearly not provided to the label's text property.

Now that we understand the problem, how can this sample apply in real world or why would anybody want to do something like this ? Basically in short, why is viewstate being utilized, if it's not needed after postback ? Button btnClickMe is not reloaded after postback, so it's safe to turn off viewstate on this control, and problem is solved.

This is a typical situation where you deliberately want viewstate to fail, apart from that i see no real use to want to maintain viewstate, which is also bloat on a control that clearly is not utilizing it.

so a rewrite ? here :

protected void Page_Init(object sender, EventArgs e)
{
if (!IsPostBack)
{
Button btnClickMe = new Button();
// note the addition of the following line
btnClickMe.EnableViewState = false;
form1.Controls.Add(btnClickMe);
btnClickMe.Text = "Click me";
}
else
{
Label label = new Label();
form1.Controls.Add(label);
}
}

Otherwise, again as per the sample code above, had we been using viewstate, then the problem would resolve itself, if we recreated the control also after postback, which is one of the basic rules of dynamic controls creation. I say rules but really it's the logical thing to do since the page is destroyed after postback and asp.net will have no recollection of controls you added dynamically since memory is cleared, so it's upto you to build it up again manually :-)

protected void Page_Init(object sender, EventArgs e)
{
// button will be created even after postback
Button btnClickMe = new Button();
btnClickMe.EnableViewState = false;
form1.Controls.Add(btnClickMe);
btnClickMe.Text = "Click me";
if (IsPostBack)
{
Label label = new Label();
form1.Controls.Add(label);
}
}

So, bottom line, a proper understanding of viewstate, knowledge of the page life cycle, so you know in what phase it's safe to build your control, which will guarantee that viewstate is reloaded into the control(so you load it prior to page_load), and you got it right. For a proper understanding of the page life cycle, you can read the following document on msdn : http://msdn2.microsoft.com/en-us/library/ms178472.aspx?wt.slv=ColumnA

Update Jan/04/2008: I forgot to mention a gotcha, so here it is :

Another gotcha you want to avoid is also the order of controls, that is, when you're loading a dynamic control, make sure the order in which you create it, has the same order when you recreate it. Confused, here let me explain better :

protected void Page_Init(object sender, EventArgs e)
{
if (IsPostBack)
{
Label label = new Label();
label.ID = "label1";
form1.Controls.Add(label);
label.Text = "label";

Button btnClickMe = new Button();
btnClickMe.ID = "button1";
form1.Controls.Add(btnClickMe);
btnClickMe.Text = "Click me";

}
else if (!IsPostBack)
{
//Now lets change the order
//during postback and we are
//recreating the controls
Button btnClickMe = new Button();
btnClickMe.ID = "button1";
form1.Controls.Add(btnClickMe);
btnClickMe.Text = "Click me";

Label label = new Label();
label.ID = "label1";
form1.Controls.Add(label);
label.Text = "label";
}
}

As you can note above, the order in which controls are added changes after postback. In this scenario what really happens ? The viewstate meant for the button is loaded into the label and the viewstate meant for the label is loaded into the button. So, you really want to be careful with the order in which you recreate your controls.

Thursday, November 26, 2009

First Post on my New Blog

First Post on my New Blog
Hi All,

I have moved to this new blog & will be posting a bit more about ASP.NET & SQL Server as it is been 2 years now that I have been working on these 2 technologies & would like to share what I have learnt in these 2 years & also keep learning myself new things through your comments & suggestions.



I would also be posting about the game of my life - the game the whole of India loves the most - Cricket & also about my birth place Bharuch, Gujarat & lots of new tech trends & in short a whole lot of stuff for everyone to enjoy...

So sit back & happy blogging....