Flip bit column in SQL#
~ is the NOT operator in SQL, so for a bit column, to flip a value the statement would be something like this:

UPDATE dbo.Users SET Optin = ~Optin WHERE Id = @id

Just found this today and after using SQL for so many years, this will definitely come in handy going forward.

Monday, March 10, 2008 12:23:46 PM (Eastern Standard Time, UTC-05:00) by Dustin #    Comments [0]  | 

 

Confirmation Buttons in .NET#
This is the simple way of doing "are you sure?" functionality in .NET:
<asp:button runat="server" id="btnSubmit" text="Do Something" onclick="btnSubmit_click" onclientclick="return confirm('Are you sure you want to do this?');">
</asp:button>
Enjoy.
Thursday, March 06, 2008 12:09:54 PM (Eastern Standard Time, UTC-05:00) by Dustin #    Comments [0]  | 

 

Nulls and UIs#
I often use simple base classes for things like address and name for more complex data structures, partly for readability and partly for easy formatting overrides. So a User class might look something like:
	class Subscriber
	{
		Base.Name Name;
		Subscriber()
		{
			this.Name = new Name();
		}
	}
	
and the Name class would look as such:
	class Name
	{
		string First = "";
		string Last = "";
		override string ToString()
		{
			return this.First + " " + this.Last;
		}
	}
	
Why not null or string.empty for the Name defaults? Quite simply those values don't play well in the UI and introducing them there seems to cause more code and potential gotchas than it solves. In the UI, this class structure is as simple as I think it can be made:
	User user = new User();
	something = user.Name.First;
	
Does the Law of Demeter apply here? No - the Name object cannot be null and cannot return null parameter values - those might be empty, but of course, we should probably checked if the User object was actually loaded correctly to catch if the entire object is null.
	User user = new User();
	if(user.Load(SomeId))
	{
		something = user.Name.First;
		somethingelse = user.Name.ToString();
	}
	else
	{
		//handle when User is still null
	}
	
I'm always looking for readability and simplicity, I think this solves both well, what do you think?
Wednesday, March 05, 2008 11:33:07 AM (Eastern Standard Time, UTC-05:00) by Dustin #    Comments [0]  | 

 

All content © 2008, Dustin Updyke


Search
On this page
Archives
By The Minute