protected
void BLL_Selected(object sender, ObjectDataSourceStatusEventArgs e) { DataTable dt = e.ReturnValue as DataTable; // do interesting stuff here... }Thursday, October 25, 2007
Getting to the result that was returned when selecting in an ObjectDataSource
Select distinct rows from a DataTable
It is probably best to describe a scenario to understand what I am trying to describe. Let's assume you have a DataTable called myDataTable that has three columns (Col1, Col2, Col3). You want to get a distinct list based on Col1 and Col2. In SQL you could do something like: Select distinct Col1, Col2 from MyTable; Believe it or not, we can do the same thing with the in memory table known as a DataTable in .Net. // populate the DataTable DataTable myDataTable = DAL.doSomeQuery();
bool distinct = true;
DataTable distinctRows = myDataTable.DefaultView.ToTable(distinct, new string[] { "Col1", "Col2" }); That is it, but it is only available in .Net 2.0.
Tuesday, October 23, 2007
ASP.NET and EventLog: Event ID issues when writing to Event Log
Literally you can copy and paste from one SQL Server to another
Easy way to restart your ASP.NET web site
Wednesday, October 10, 2007
Image alignment in HTML / CSS
<
img border="0" src="myImage.gif" style="vertical-align:middle"/>my text that is to the right of the image.
Finding column references in SQL Server
if exists (select * from dbo.sysobjects
where id = object_id(N'[dbo].[usp_FindColumnUsage]')
and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[usp_FindColumnUsage]
GO
CREATE PROCEDURE [dbo].[usp_FindColumnUsage] @vcTableName varchar(100), @vcColumnName varchar(100) AS /************************************************************************************************ DESCRIPTION: Creates prinatable report of all stored procedures, views, triggers and user-defined functions that reference the table/column passed into the proc. PARAMETERS: @vcTableName - table containing searched column @vcColumnName - column being searched for REMARKS: To print the output of this report in Query Analyzer/Management Studio select the execute mode to be file and you will be prompted for a file name to save as. Alternately you can select the execute mode to be text, run the query, set the focus on the results pane and then select File/Save from the menu.
This procedure must be installed in the database where it will be run due to it's use of database system tables.
USAGE: usp_FindColumnUsage 'jct_contract_element_card_sigs', 'contract_element_id' AUTHOR: Karen Gayda
DATE: 07/19/2007
MODIFICATION HISTORY: WHO DATE DESCRIPTION --- ---------- ------------------------------------------- *************************************************************************************************/ SET NOCOUNT ON
PRINT '' PRINT 'REPORT FOR DEPENDENCIES FOR TABLE/COLUMN:' PRINT '-----------------------------------------' PRINT @vcTableName + '.' +@vcColumnName
PRINT '' PRINT '' PRINT 'STORED PROCEDURES:' PRINT ''
SELECT DISTINCT SUBSTRING(o.NAME,1,60) AS [Procedure Name] FROM sysobjects o INNER JOIN syscomments c ON o.ID = c.ID WHERE o.XTYPE = 'P' AND c.Text LIKE '%' + @vcColumnName + '%' + @vcTableName + '%' ORDER BY [Procedure Name] PRINT CAST(@@ROWCOUNT as Varchar(5)) + ' dependent stored procedures for column "' + @vcTableName + '.' +@vcColumnName + '".'
PRINT'' PRINT'' PRINT 'VIEWS:' PRINT'' SELECT DISTINCT SUBSTRING(o.NAME,1,60) AS [View Name] FROM sysobjects o INNER JOIN syscomments c ON o.ID = c.ID WHERE o.XTYPE = 'V' AND c.Text LIKE '%' + @vcColumnName + '%' + @vcTableName + '%' ORDER BY [View Name] PRINT CAST(@@ROWCOUNT as Varchar(5)) + ' dependent views for column "' + @vcTableName + '.' +@vcColumnName + '".'
PRINT '' PRINT '' PRINT 'FUNCTIONS:' PRINT ''
SELECT DISTINCT SUBSTRING(o.NAME,1,60) AS [Function Name], CASE WHEN o.XTYPE = 'FN' THEN 'Scalar' WHEN o.XTYPE = 'IF' THEN 'Inline' WHEN o.XTYPE = 'TF' THEN 'Table' ELSE '?' END as [Function Type] FROM sysobjects o INNER JOIN syscomments c ON o.ID = c.ID WHERE o.XTYPE IN ('FN','IF','TF') AND c.Text LIKE '%' + @vcColumnName + '%' + @vcTableName + '%' ORDER BY [Function Name] PRINT CAST(@@ROWCOUNT as Varchar(5)) + ' dependent functions for column "' + @vcTableName + '.' +@vcColumnName + '".'
PRINT'' PRINT'' PRINT 'TRIGGERS:' PRINT''
SELECT DISTINCT SUBSTRING(o.NAME,1,60) AS [Trigger Name] FROM sysobjects o INNER JOIN syscomments c ON o.ID = c.ID WHERE o.XTYPE = 'TR' AND c.Text LIKE '%' + @vcColumnName + '%' + @vcTableName + '%' ORDER BY [Trigger Name] PRINT CAST(@@ROWCOUNT as Varchar(5)) + ' dependent triggers for column "' + @vcTableName + '.' +@vcColumnName + '".'
GO
Tuesday, October 9, 2007
Adding AJAX.Net to existing ASP.Net Web Site
Monday, October 8, 2007
Conditional Compilation to run Windows Service as an application
Conditional Compilation is a concept that has been around since C and C++. The idea is that you can define variables, control flow, etc for what gets compiled and what does not.
This concept can be illustrated by looking at testing of Windows Services in Visual Studio 2005. It is time consuming and just no fun to write code as a Windows Service as it cannot be run directly in Visual Studio. The solution I propose is to use Conditional Compilation to allow the Windows Service to be ran as a Windows Service or Windows Form Application. To do this, see below. // NOTE: Add RunAsApp to Conditional Compiler Symbols under the Build tab on the Project properties. #if (RunAsApp) // To test as an app MyServicee app = new MyService(); Application.Run(app); #else // To test as a Service ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new MyService() }; ServiceBase.Run(ServicesToRun);