Sometimes you just have to save files in the database. The reason? Because "Simon" said so. So without further ado, here is a simple example on how to compress files using C# and
SharpZipLib:
Read the full article
here.
With the new extension method feature of C# 3.5 it's now easy to extend your classes for additional functionality. Here are some useful functionalities to add to your favorite System.String:
Read the full article
here.
ThreadAbortException:
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
Read the full article
here.
Taken from the
MSDN documentation:
The finally block is useful for cleaning up any resources allocated in the try block as well as running any code that must execute even if there is an exception.
So in other words whatever code you have in your "finally" block will always execute when an exception occurs, right? Wrong. The correct answer is - it depends on the error...
Read the full article
here.
ReSharper is an add-in for Microsoft Visual Studio .NET 2003™ that brings intelligent C# coding assistance, real-time error highlighting, and refactoring features to this popular development platform.
read more >>
What I learned from reading other .Net blogs was not to focus on MS Architecture patterns alone but, to also read other architecture patterns like this -
J2EE Transfer Object pattern. I got this site from
Frans Bouma, who recommended this link, in Paul Wilson's blog entry about
Avoiding Reflection.
for (int i = 0; i < table.Count; i ++)
{
string s;
s = Convert.ToString(table[i, "fsectcd"]);
if(s[0] != '*')
condition += " or " + sectionCondField + " = '" + s.Trim() + "'";
s = Convert.ToString(table[i, "fsite"]);
if (s[0] != '*' && condition.IndexOf("'" + s.Trim() + "'") < 0)
condition += " or " + sectionCondField + " = '" + s.Trim() + "'";
}
I just found this code in our base class. What this code does is to create a where condition for our sql statement (for checking some security??? have no idea, really). This is only one part of the original code. The process was to retrieve records from the database and build a where condition. This is what the where condition will look like:
(fieldname = 'some value' or fieldname = 'another value' or ...)
Now, what do you think is the mistake here? When I saw this code I smiled. :-) Just imagine creating tons of String instances when executing this code. For a thousand records retrieved, how many instances do you think will be created? hehehe :-)
I will call this the "PowerBuilder Pattern" coz this was based on an existing PowerBuilder ancestor design of one company. I was shocked when they told me about this design to be implemented in .Net. Cheers! :-)
Good for reporting...try it!
Use Northwind
SELECT
P.ProductID,
P.ProductName,
P.UnitsInStock,
(SELECT SUM(UnitsInStock) FROM Products WHERE ProductID <= P.ProductID) AS UnitsInStockRunningTotal
FROM Products P
Imagine
your business entities would be something like this:
public
string Firstname
{
get { LoadInfo();
return _firstname; }
set
{
LoadInfo ();
if (_firstname !=
value)
{
_firstname =
value;
ExecuteQuery("UPDATE Table SET Firstname = '" + _firstname
+ "' WHERE ID = " + _id.ToString());
}
}
}
public
string Lastname
{
get { LoadInfo(); return _lastname;
}
set
{
LoadInfo ();
if (_lastname !=
value)
{
_lastname =
value;
ExecuteQuery("UPDATE Table SET Lastname = '" +
_lastname + "' WHERE ID = " + _id.ToString());
}
}
}