SCOPE_IDENTITY() returns the last generated *identity* value in the current scope (function, stored proc., trigger, etc.). Identity columns need to be of type bigint, int or smallint and are not compatible with type uniqueidentifier (i.e. you can't assign an integer to a variable defined as a uniqueidentifier).
So, if you're asking SQL Server to give you last identity inserted and then assigning that to a variable previously declared as a uniqueidentifier, you'll end up with the compatibility error that you're receiving.
Tuesday, May 05, 2009
Wednesday, April 08, 2009
Overloading methods in WCF
Service oriented development is different than the Object oriented programming. Overloading methods is possible in WCF, but not recommended.
To make it work in WCF, you'll need to add Name property
To make it work in WCF, you'll need to add Name property
[ServiceContract]
public interface ICalendarService
{
[OperationContract(Name = "GetScheduledEventsByDate")]
ScheduledEvent[] GetScheduledEvents(DateTime date);
[OperationContract(Name = "GetScheduledEventsByDateRange")]
ScheduledEvent[] GetScheduledEvents(DateTime start, DateTime end);
}
For more info: here
SQL: Return limit Rows
In the asp.net application, i found the good way to return limit rows from data table is to use the ROWCOUNT
CREATE PROCEDURE GetContacts ( @ModuleID int, @maxrows int = 0 ) AS SET ROWCOUNT @maxrows SELECT ItemID, CreatedDate, CreatedByUser, Name, Role, Email, Contact1, Contact2 FROM Contacts WHERE ModuleID = @ModuleIDFor more info: http://authors.aspalliance.com/stevesmith/articles/sprowcount.asp
Wednesday, April 01, 2009
Change the author initial when review comments
- On the Review tab, in the Tracking group, click the arrow next to Track Changes, and then click Change User Name.
- Click Popular.
- Under Personalize your copy of Office, change the name or initials that you want to use in your own comments.
Thursday, March 12, 2009
FxCop: exclude the naming rule for some words
I used the Iframe identifier in my project and FxCop did not like it.
The way to get around this without rename everywhere is to include a custom dictionary named CustomDictionary.xml in the project directory.
for more info: http://msdn.microsoft.com/en-us/bb264492.aspx
The way to get around this without rename everywhere is to include a custom dictionary named CustomDictionary.xml in the project directory.
for more info: http://msdn.microsoft.com/en-us/bb264492.aspx
Friday, March 06, 2009
FxCop to Excluded in Source
There are 2 ways to make the rule exceptions in FxCop. One way is to update the .fxcop file. Another way is to update your source code.
For Excluded in Source, add add the following line on top of the method/function/data members.
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Need to set Specialties collection")]
Also, need to declare System.Diagnostics.CodeAnalysis in your source file.
using System.Diagnostics.CodeAnalysis;
For Excluded in Source, add add the following line on top of the method/function/data members.
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Need to set Specialties collection")]
Also, need to declare System.Diagnostics.CodeAnalysis in your source file.
using System.Diagnostics.CodeAnalysis;
Wednesday, January 28, 2009
StringComparison
Here is a great article on when to use the StringComparison.
http://msdn.microsoft.com/en-us/library/ms973919.aspx
DO: Use StringComparison.Ordinal or OrdinalIgnoreCase for comparisons as your safe default for culture-agnostic string matching.
DO: Use StringComparison.Ordinal and OrdinalIgnoreCase comparisons for increased speed.
DO: Use StringComparison.CurrentCulture-based string operations when displaying the output to the user.
DO: Switch current use of string operations based on the invariant culture to use the non-linguistic StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase when the comparison is linguistically irrelevant (symbolic, for example).
DO: Use ToUpperInvariant rather than ToLowerInvariant when normalizing strings for comparison.
DON'T: Use overloads for string operations that don't explicitly or implicitly specify the string comparison mechanism.
DON'T: Use StringComparison.InvariantCulture-based string operations in most cases; one of the few exceptions would be persisting linguistically meaningful but culturally-agnostic data.
http://msdn.microsoft.com/en-us/library/ms973919.aspx
DO: Use StringComparison.Ordinal or OrdinalIgnoreCase for comparisons as your safe default for culture-agnostic string matching.
DO: Use StringComparison.Ordinal and OrdinalIgnoreCase comparisons for increased speed.
DO: Use StringComparison.CurrentCulture-based string operations when displaying the output to the user.
DO: Switch current use of string operations based on the invariant culture to use the non-linguistic StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase when the comparison is linguistically irrelevant (symbolic, for example).
DO: Use ToUpperInvariant rather than ToLowerInvariant when normalizing strings for comparison.
DON'T: Use overloads for string operations that don't explicitly or implicitly specify the string comparison mechanism.
DON'T: Use StringComparison.InvariantCulture-based string operations in most cases; one of the few exceptions would be persisting linguistically meaningful but culturally-agnostic data.
Thursday, January 22, 2009
Use delegate to sort the generic list (collection)
Here is an example of how to use the delegate to sort the list:
returnList.Sort(delegate(IMyClass x, IMyClass y)
{
return String.Compare(x.Name, y.Name);
});
So, instead of override the ICompare, you can use this short-cut to return a sorted list.
Here is how to just make your Thing class implement IComparable, implementing the CompareTo method like this:
public int CompareTo(Thing other)
{
return Name.CompareTo(other.Name);
}
returnList.Sort(delegate(IMyClass x, IMyClass y)
{
return String.Compare(x.Name, y.Name);
});
So, instead of override the ICompare, you can use this short-cut to return a sorted list.
Here is how to just make your Thing class implement IComparable
public int CompareTo(Thing other)
{
return Name.CompareTo(other.Name);
}
Subscribe to:
Posts (Atom)