Skip to content

Upgrading from Report Viewer 2005 to Report Viewer 2008

If  you have both the Report Viewer 2005 control and the Report Viewer 2008 control installed you may see the following error message:” “.

To resolve this, change the version of the HttpHandler module from:

to:

And add the following entry into your web.config:

Function Decorators for dummies

The best explanation for Python’s function decorators can be found here:

http://personalpages.tds.net/~kent37/kk/00001.html

I was mystified about decorators that took arguments until I read this presentation. Why can’t more technical writers write like Kent? Simple, clear and to the point.

Working with JavaScript

When you are working on JavaScript UI libraries, or any code that creates dynamic user-interface elements, there are 3 primary ways for clients to work with your JavaScript.

1. You can have your expect the client to provide you with the ID of the element to render in.
2. You can output the controls directly onto the page using some for of document.write().
3. You can have a server side control output the JavaScript for you.

Example of 1:

<script>
var tree;
function treeInit() {
tree = new YAHOO.widget.TreeView("treeDiv1");
var root = tree.getRoot();
var tmpNode = new YAHOO.widget.TextNode("mylabel1", root, false);
var tmpNode2 = new YAHOO.widget.TextNode("mylabel1-1", tmpNode, false);
tree.draw();
}
</script>

Example of 2: ActiveWidgets

<script>
// create ActiveWidgets component
var obj = new AW.UI.Button;
// set the display text
obj.setControlText("Click me");
// assign click event handler
obj.onControlClicked = function(){
this.setControlText("Hello World!");
};
// add component to the page
document.write(obj);
</script>

SQL: Addition or concatenation

select ‘0001’ + 1

What is the result?

Logically, it could be ‘00011’ or 2. It should be ‘00011’ if the + is interpreted as concatenation, , and 2 if the + is iterpreted as addition and (‘0001’ is implicitly cast to a number).

The result is 2. Reminder, addition takes precedence over concatenation.

edit: Upon further examination, the issue isn’t operator precedence but data type precedence.

The data type precedence rules determine which operands get converted to the other.

  • sql_variant (highest)
  • datetime
  • smalldatetime
  • float
  • real
  • decimal
  • money
  • smallmoney
  • bigint
  • int
  • smallint
  • tinyint
  • bit
  • ntext
  • text
  • image
  • timestamp
  • uniqueidentifier
  • nvarchar
  • nchar
  • varchar
  • char
  • varbinary
  • binary (lowest)

Varchar vs Char watchout

This happens all the time in the world of developers. You’ve been working with a technology for so long you think you know everything (enough) about it. Then suddenly, poof, something’s not working the way you expect it to. Before you go crazy and reassess all your previous understanding, calm done. My usually approach is to simplify things and do some experiments. This works all the time.

My problem: I was trying to pad a number with zeros and make it a fixed width but it wasn’t working.

This was my original non-working code:
1. select RIGHT((‘0000’ + CAST(num1 as char(4))), 4) from #TEMP_TBL1 

This code works:
2. select RIGHT((‘0000’ + CAST(num1 as varchar(4))), 4) from #TEMP_TBL1

See the difference? Yes, in the working snippet I cast the number to a varchar. The trouble with Char is that it right-gets padded with spaces if the number is less than the specified width. d’oh! I realized this during my trip home on the subway. My other false assumptions were that I wasn’t using the RIGHT function correctly, something was wrong with my concatenation, etc.

My experiments didn’t shed much light into the problem because in trying to simplify things, I removed the CAST, which perplexed me further.

select RIGHT((‘00002’), 4) from #TEMP_TBL1 select RIGHT((‘0000’ + ‘8’), 4) from #TEMP_TBL1With the benefit of hindsight, this test makes it clear what the difference is in using varchar vs char.select (‘0000’ + CAST(num1 as varchar(4)) + ‘0’) from #TEMP_TBL1select (‘0000’ + CAST(num1 as char(4)) + ‘0’) from #TEMP_TBL1

Formatting output in SQL Server

If you need your query results formatted in a specific justification try this little expression.

To right justify:
RIGHT(SPACE(len) + str, len)
To left justify:
LEFT(str + SPACE(len), len)

Datagrid not retaining viewstate on postback

Retrieved from: http://vspug.com/kwanl/2007/05/24/datagrid-not-retaining-viewstate-on-postback/

I haven’t done much DataGrid programming in the past but it’s used quite a bit at my new job. I thought I was pretty proficient at ASP.Net 1.1 but I was having some trouble getting the DataGrid viewstate to work. The problem was when you have AutoGenerateColumns set to false you have to do a little bit of extra work for the viewstate to load, you need to set up the columns on each page load.

http://www.velocityreviews.com/forums/t111954-net-datagrid-contents-lost-on-postback.html