Wednesday, May 8, 2013

Difference between @@IDENTITY vs SCOPE_IDENTITY() in SQL Server

 

@@IDENTITY will return the last identity value inserted into a table in the users current session. While @@IDENTITY is limited to the current session, not limited to the current scope. If an other user insert a row in the same table after you, you might get that Identity value.

Or Second scenario is if you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it. So from the above discussion
it is apparent that what ever that Identity value you got my be or may not be correct. To solve that problem we can use Scope_Identity().

SELECT SCOPE_IDENTITY(), returns the last IDENTITY value created in the current session, but it will also limit it to your current scope as well. i.e You are gauranteed to get the last identity value you inserted into the table.

Thursday, August 18, 2011

XSD 2d buug

If you get array related stuff like:

Unable to generate a temporary class (result=1).
error CS0030: Cannot convert type 'Data[]' to 'Data'
error CS0029: Cannot implicitly convert type 'Data' to 'Data[]'


read on, otherwise you might be facing something different.

The problem is the xsd.exe tool has a bug when it comes to mapping to a multidimensional array. In most cases you can easily fix it by hand.

In my case, I ran a search on the Data type name in the generated file, and I found this:

[System.Xml.Serialization.XmlArrayItemAttribute("Data", typeof(Data), IsNullable=false)]
public Data[][] Row



As it can be seen, the type of the elements of a Data[][] array is not Data, but Data[]. The only change required was:

[System.Xml.Serialization.XmlArrayItemAttribute("Data", typeof(Data[]), IsNullable=false)]
public Data[][] Row



Happy coding, and hopefully we'll be spared of this kind of framework bugs in the future.

Monday, January 24, 2011

Cross Browser Script

// Check Empty Fields..

function CheckEmpty(val)

{

if(val.replace(/^\s*|\s*$/g,‘ ’)==‘ ’)

{

return false;

}

return true;

}

// new function to disable spacebar on cross browserfunction

DisableSpacebar(evt)

{

evt = (evt) ? evt : (window.event) ? event : null;

if (evt)

{

var charCode = (evt.charCode) ? evt.charCode :

((evt.keyCode) ? evt.keyCode :

((evt.which) ? evt.which : 0));

if(charCode==32)

{

return false;

}

}

}
///function to check number on cross browsers

function NumberOnly(evt)

{

evt = (evt) ? evt : (window.event) ? event : null;

if (evt)

{

var charCode = (evt.charCode) ? evt.charCode :((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));

if(charCode>47 && charCode<58)

{

return true;

}

else if(charCode==8||charCode==9||charCode==17)

{

return true;

}

else if(charCode>32 && charCode<41|| charcode==46)

{

return true;

}

else if(charCode==16||charCode==18 || charCode==19||charCode==27)

{

return true;

}

else {

return false;

}

}

}

Monday, November 30, 2009