NovelProjects

Wednesday, January 13, 2010

C# custom Attribute on an enum object

Today I was working with an enum on a class object and I wanted something more than just the default MyObject.MyEnum.ToString() (which returns the name of my enum as defined in code). Here was my enum:


public enum ImportType
{
FullProduct = 1,
ImageProduct = 2,
PriceProduct = 3,
Customer = 4
}

I wanted something more descriptive and readable than 'FullProduct' so I asked my good buddy Google. That lead me to this article. After adding in a couple classes my enum now looks like:

public enum ImportType
{
[Description("Full Product Import")]
FullProduct = 1,
[Description("Product Image Import")]
ImageProduct = 2,
[Description("Product Price Import")]
PriceProduct = 3,
[Description("Customer Import")]
Customer = 4
}

Now on my front end I can call


<%# EnumHelper.GetDescription((ImportType)Eval("Type")) %>

and get 'Full Product Import' instead of 'FullProduct'

Monday, December 14, 2009

SqlDataAdapter.Fill method running slow

I ran into an issue today where I was using the SqlDataAdapter.Fill method and it was taking an unusually long time to return back. I ran the query in Management Studio and it was fast, as I expected. After a little googling I ran across this post where it was mentioned to run:


DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE

This clears out the memory buffers and procedure cache.


After doing that my SqlDataAdapter.Fill method ran much faster!

Wednesday, July 29, 2009

ASP.NET submit button double click

Just wanted to post up a quick page I found when I was looking to prevent double clicking on a submit button.


http://dotnetchris.wordpress.com/2008/08/07/the-dreaded-aspnet-submit-button-double-click/


This approach is fairly simple; just use two buttons and update the visibility to achieve the affect.

Tuesday, July 21, 2009

ASP.NET 3.5's ListView Control

Here's a link to a 4 guys series (much like the famous 18 part series on the DataGrid) that goes over the ListView control. It's new to .net as of 3.5.



It looks like it has the power of the DataGrid functionality, plus some, with the power to control the rendering like the Repeater (for you table haters).



I'm just getting ready to use it for the first time so I'm anxious to see how it's going to come out in the end.

Monday, June 29, 2009

SQL Stored Procedure for looping through rows

Here is some code for an sql stored procedure for looping through a result set of rows and then executing some code foreach row.


ALTER PROCEDURE [dbo].[DeleteMilestone]
-- Add the parameters for the stored procedure here
@ApplicationId uniqueidentifier,
@MilestoneId uniqueidentifier
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

DECLARE @rowcount int --Declared to number of records

DECLARE @ProjectId uniqueidentifier
DECLARE @TaskId uniqueidentifier
DECLARE @OrderNum int

-- get the ProjectId
SELECT @ProjectId=ProjectId FROM Milestones WHERE ApplicationId=@ApplicationId AND MilestoneId=@MilestoneId

-- get the number of MilestoneTasks that are open (open Tasks' OrderNum will not be 0)
SELECT @rowcount=COUNT(TaskId) FROM MilestoneTasks WHERE MilestoneId=@MilestoneId AND OrderNum<>0

WHILE @rowcount > 0
BEGIN
-- select tasks that are still open (open Tasks' OrderNum will not be 0)
-- selecting the top 1 should give me the highest order milestone task
SELECT TOP 1 @TaskId=TaskId FROM MilestoneTasks WHERE MilestoneId=@MilestoneId AND OrderNum<>0 ORDER BY OrderNum

-- select max ordernum <>0 from ProjectTasks
SELECT @OrderNum=MAX(OrderNum)+1 FROM ProjectTasks WHERE ProjectId=@ProjectId AND OrderNum<>0

-- update the OrderNum of this Task in ProjectTasks
UPDATE ProjectTasks SET OrderNum=@OrderNum WHERE ProjectId=@ProjectId AND TaskId=@TaskId

-- update the OrderNum of this Task to 0 in MilestoneTasks
UPDATE MilestoneTasks SET OrderNum=0 WHERE MilestoneId=@MilestoneId AND TaskId=@TaskId

-- update the number of MilestoneTasks that are open (open Tasks' OrderNum will not be 0)
SELECT @rowcount=COUNT(TaskId) FROM MilestoneTasks WHERE MilestoneId=@MilestoneId AND OrderNum<>0

END

DELETE FROM Milestones WHERE ApplicationId=@ApplicationId AND MilestoneId=@MilestoneId

END

Thursday, April 30, 2009

Rowset string concatenation

I was looking for some info on making an concatenated string with SQL and ran across a great resource here: http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx.


I was able to create a function just like in the article which saved me from have to make unnecessary database calls.

Monday, April 13, 2009

Visual Studio 2008: The Project Location is Not Trusted

I ran into a situation today after formatting my computer where I opened a VS project on a mapped network drive and received the error about the project location not being trusted.


After lots of researching I found an article that helped me a little bit: check it out here.


Like I said, it helped me a little bit. I had to go further and experiment with different command line calls because what was in the link above did not work for me. I ended up using two commands before I finally got the warning message to go away. Here are those lines:


caspol -rg 1.3.1
caspol -m -ag 1.3 -allcode FullTrust

The first line removes the policy at 1.3.1. Then I add a new policy in that gives the All Code group full trust. 1.3 is the Internet zone. I tried adding the same thing to the Intranet zone but that did not work for me.


Hope this helps for anyone else running into this problem.