Linking to a subreport in Crystal Reports through .NET
Working with Crystal Reports sucks. If you've stumbled upon this page in a desperate attempt to find help for Crystal Reports, you know that it sucks. It behaves, at times, erratically. The support for it is next to nonexistent. If it weren't for Google, it would be amazing that anyone would successfully write a Crystal Report whether using version 7, 8, 10, or any other incarnates of it. Here's an example of how to utilize a subreport within the built in .NET 2008 version of Crystal Reports.
Read more
Check if a directory is empty in .NET 2008
For one reason or another, we may need to have our programs intelligently manage hard disk directory structure on the end user's PC. This would include such techniques as checking if a directory exists, creating a directory if it doesn't exist, clearing a directory, etc. This is actually a very easy process in .NET 2008 given the built in resources provided with Visual Studio. I'm going to be using VB.NET in my very simple example to check for the existence of a file directory.
Read more
Using a table variable in your SQL stored procedure
There comes a time in any programmer's life, when writing SQL code beyond a beginner level, that a temporary table is needed. Be it to manage complex update processes before committing to any transaction, or whatever the case may be, I'm going to discuss using a table variable as an efficient and versatile alternative to using a temporary table.
Why do we not like using temporary tables? Well, for one, they require some type of garbage collection cleanup. Nobody likes having a bunch of useless orphaned temporary tables hanging around their well structured SQL database, right? Also, a temporary table takes up SQL server space and just isn’t quite as efficient as other SQL friendly solutions.
Using SQL 2008, a table variable is easy to manage. Just declare it as you would any other type of SQL variable.
DECLARE @table1 TABLE (
CustID uniqueidentifier,
CustType varchar(50),
NewName varchar(50)
)
Now that you’ve got a SQL table variable declared, we’ll want to insert datarows into it – right? Let’s write an insert command within our stored procedure.
INSERT INTO @table1
SELECT [CustID], [CustType], ‘’
FROM Customer
Now you’ve got your SQL table variable populated with some data. In this example, we’ll now run a series of SQL update queries against this temporary table. You would treat it as you would any other SQL table – whether it be a variable or not.
UPDATE @table1
SET NewName = ‘East’
WHERE CustType = ‘1’
UPDATE @table1
SET NewName = ‘West’
WHERE CustType = ‘2’
You can even run joins such as INNER JOIN, LEFT JOIN, RIGHT OUTER JOIN, etc. against this table variable with some of your established tables. You’ll just need to provide a table name alias (in this case T1).
SELECT *
FROM Customer
INNER JOIN @table1 AS T1 ON T1.NewName = Customer.Name