Thursday, June 14, 2007

ASP.NET 2.0 Data Controls Not Updating - Solution

Couple of extra hooks for searches: GridView, DetalsView, FormView, ASP.NET 2.0, Not Updating, Problem

Please keep in mind these solutions were put into use after much trial & effort and a LOT of google/msdn searching. Also, I suggest these solutions because they worked for me, NOT because I have a deep understanding of why they work (I have a passing understand, but nothing worth writing about).

Solution: The DataKeyNames property of the data control you're using should be set to the Primary field key of the table you're updating. Found the obscure reference here.

Alt Solution: I'm not particularly fond of this solution. It involves making a change to the properties of the (SQL Server) database you're using. In SQL Server 2005 Management Studio, setting ANSI NULLS Enabled = true seems to remove the updating problem as well, but this effects the database and potential pre-written logic on a much larger scale. Make sure you understand the repercussions of changing DB options. Why this works might be discerned from here.

Labels: , , ,

Thursday, March 22, 2007

Ajax Control Toolkit 10301 Fun

And by fun I actually mean a searing pain in the ass.

As much as I'd love to vent about MS's tendency to over complicate the simplest of tasks, I've chosen my poison and need to deal with it.

The problem: Updated my Ajax Control Toolkit to version 10301 and nothing worked. Got some Sys is not defined error.

Path to solution: Google is becoming decreasingly helpful with code problems. Either their algorithms are getting rusty or sites/forums (*cough* Microsoft *cough*) are purposefully hiding data from them. If true, the former is disturbing and the latter is deplorable. Then there's the remote possibility that my search skills are withering... no.

Solution: Cut and paste sections from the web.config that came with the latest toolkit to see if anything would magically make things work again.

This did it:

<system.web>
<!--Other stuff-->
<httphandlers>
<remove verb="*" path="*.asmx">
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false">
</httphandlers>
<httpmodules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
</httpmodules>
</system.web>

What this really comes down to is that I don't understand .NET innards... yet. I do however think the trip is unnecessarily painful (for something they''re just going to dump in a few years anyway). I still remember when RDO was the wave of the future.

A.D.D.-Techno-schizophrenic bastards. Wouldn't be so bad if I didn't so closely resemble them.

Labels: , , ,

Tuesday, March 06, 2007

Correlated Subquerys

Ah, the wonderful Correlated Subquery...

This discovery neared completion with a google search for "t-sql select subquery parameter from select". Which returned a link to this article (http://www.databasejournal.com/features/mssql/article.php/3485291).

Why did I need subquery that made use of data from the outer query?

I've got a calendar table built using this article (http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-calendar-table.html).
Now I have a need to return data from the Quarter Name column and the last date in that quarter for each line item. Sure there are lots of ways to do it, but a solution modified from the first referenced article allows me to do it in a single line of SQL.

I'd previously created a view (view_Quarters) to return DISTINCT quarter names (and id) for simplified inclusion in other queries.

Here's the Code:
SELECT
qn, qid, (SELECT TOP 1 dt FROM Calendar WHERE qid = vQ.qid ORDER BY dt DESC) LastDay
FROM
view_Quarters vQ ORDER BY qid

I knew what I wanted to happen ahead of time, but didn't know if it had been implemented SQL (ANSI or the flavor of my choice). It's always incredible to see that someone else had laid the groundwork for most of the problems you'll run into and even better with a good search engine to make that work easily available. Thank you DatabaseJournal, ASP.FAQ and Google.

Labels: ,

Wednesday, February 14, 2007

I LOVE O'Reilly Safari Library

A year ago I extolled the Safari O'Reilly Bookshelf for granting the ability (depending on subscription) to have complete access to 30 technical books at once (each with a required stay on ones "favorites" for at least a month). In addition to O'Reilly's HUGE stable of titles, publishers like Microsoft Press and Addison Wesley also made their titles available.

The current publisher list includes (but is not limited to): O'Reilly, Addison Wesley, Sams, Prentice Hall, Que, Cisco Press, Microsoft Press,Peachpit Press, New Riders Publishing, Alpha Books, Course Technology, IBM Press, Macromedia, Adobe Press, Syngress, Financial Times Prentice HallMuska & Lipman, MySQL Press, No Starch, Novell Press, Premier Press, Prima Publishing, SitePoint, & Wharton School Publishing. The only one missing of note (to me) is Apress, but they have their own service.

Towards the end of last year, a new subscription option was enabled: The Safari Library. Unrestricted access to ALL titles [GLEE!!]. Currently going for $439.99 (10 hardcovers) it was a no brainer. I was regularly maxing out my bookshelf (30 books), but now have over 80. You might think one can't possibly consume that much information in any reasonable time period, but it's not about reading every book from cover to cover. It's about taking the information you need from every resource available. Now my resources are almost unlimited. Though my quick answers frequently come from Google Groups (formerly Deja) and a good bit of R&D happens via web searches, there is still no real equivalent to a (good) published text (or 5) on a given topic. What about the books with Code Samples, etc on an accompanying CD/DVD? Available via a link at the top of every page. Frequently, these links go the the authors web site with additional info as well. In addition to regularly published titles, one also has access to "Safari Guides", "Short Cuts" and "Rough Cuts".

I've been labeled as obsessive about learning on more than one occasion. Knowledge without application, however, is useless. The more I learn the more I can do. With tools like the Safari Library, I may have more than I can ever use, but I'll almost always have what I need.

As for gripes about the service. No major ones. The Library Subscription comes with 5 tokes a month. A token usually allows for the download of 1 chapter, sometimes a subsection. Each token expires if not used in 3 months. I find the token system a bit too restrictive, but use them because they expire if I don't. Downloaded chapters are watermarked pdfs with account information, allowing any copies in the wild to be traced back to the source. I like this approach Much better than password protected pdfs, but reading a chapter at a time can be a pain. Some books I read through, others I hop around looking for topics I need. The greatest flexibility is available while online.

Labels: , , ,

Monday, September 25, 2006

Wandering Off

I tend to wander. Be it in downtown Beijing or just reading a book.

I'm still reading Java for Artists. I made it a couple of pages in several hours. Here's a rundown of the journey.

Chapter 3 talks about the Spiral Development Cycle.


The same 3 steps (plan, code, test) are repeated to build and maintain forward progress. And although the code and testing have peristent artifacts (the code itself), the plan steps are layed out in tables in the book. Somewhere along the line I decided I wanted to be abkle to do everything in text files (Starting from scratch). I'd like continue this process after I'm done with the book, but how can I create structured data in a text file? XML. Damn it! Now I have to go read up on XML again. How many times does this make now? Use it or lose it. A google search on XML turns up a favorite site of mine (w3schools.com). Of Course, I can't just read about XML (since alone it won't really meet my needs). This leads me to tutorials on XML, XPath, XSLT and XSL-FO (that's a new one to me).

I probably shouldn't be watching tv while I'm doing all of this...

So now I'm working on the XML and XSL that I hope will make up my plan list. Java? Yeah, I'll get back to that eventually. At the moment I can't even get the XSL to properly transform the XML. I am Clearly a masochist.

Here's the xml to this point:


<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="RobotRat.xsl"?>

<dev_plan xmlns="http://brian.donoho.com/xml/">
<name>RobotRat</name>
<prog_lang>Java</prog_lang>
<step id="1" phase="1">
<design_consideration>
Program Structure
</design_consideration>
<design_decision>
One class will contain all the functionality
</design_decision>
</step>

<step id="2" phase="1">
<design_consideration>
Creating the Java application class
</design_consideration>
<design_decision>
The class name will be RobotRat. It will contain a “public static void main(String[] args){ }” method.
</design_decision>
</step>

<step id="3" phase="1">
<design_consideration>
constructor method
</design_consideration>
<design_decision>
Write a class constructor that will print a short message to the screen when a RobotRat object is created.
</design_decision>
</step>

<step id="" phase="">
<design_consideration>
</design_consideration>
<design_decision>
</design_decision>
</step>

<step id="" phase="">
<design_consideration>
</design_consideration>
<design_decision>
</design_decision>
</step>

</dev_plan>


And the xsl:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2><xsl:value-of select="dev_plan/name" /> Dev Plan</h2>
<table border="1">
<tr>
<th>Check-Off</th>
<th>Design Consideration</th>
<th>Design Decision</th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<xsl:for-each select="dev_plan/step">
<tr>
<td></td>
<td><xsl:value-of select="design_consideration" /></td>
<td><xsl:value-of select="design_decision" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>


After hours of trial and error. I find that removing the xmlns attribute from the dev_plan element makes everything work. Do I go and figure out why it was breaking things or do I move on with what I should be doing? ROFLOL

Before I get back to figuring out what went wrong with the xml, I should mention that I took another side trip to figure out / remember how display code on a web page. Doing a google search for displaying HTML code brought me to the xmp tag which I'd never heard of, but didn't work for me (meaning, just throwing it around the raw code didn't work). Finally I found an online tool to Display HTML sample code. Thank You Christopher Brewer ^_^

After being left unfulfilled by the explaination of XML Namespaces at w3schools (first time for everything), I found this article at xml.com. Interesting, but I still don't quite get it. Several variations on the xml still result in it not making it through the xsl. I know how to make it work, but I want to understand what's going on when it's not working. After reading Ronald Bourret's XML Namespaces FAQ I understand namespaces themselves a bit more, and get the impression that mine is declared properly, but not why the xsl "breaks".

After doing a search for "XML Namespaces breaks xslt xsl transform" I found a link to a thread that explains the problem and the solution (I didn't want). It looks like my options are to remove the default namespace from my xml doc OR prefix everything in both documents.
After a few more unsuccessful tests and in the interst of continuing my java studies I will remove the default xmlns attribute. Fortunitely this R&D won't be wasted as I will be visiting XML in a later study session.

Labels: , ,

Tuesday, September 19, 2006

Java compile error because of text encoding

I have the magical ability to find every possible error in the course of learning about something. Take for example todays exploits. I'm developing on windows XP using Notepad++.

I'm reading "Java For Artists—The Art, Philosophy, and Science of Object-Oriented Programming" and given the simple code below:

-----------------------------------------------------------------------------------------------
Example 2.1: SampleClass.java

package com.pulpfreepress.jfa.chapter1;

import java.util.*;

public class SampleClass {
/**************************************
Class and instance field declarations
***************************************/
public static final int CONST_VAL = 25;
private static int class_variable = 0;
private int instance_variable = 0;

public SampleClass(){
System.out.println("Sample Class Lives!");
}

public static void setClassVariable(int val){
class_variable = val;
}

public static int getClassVariable(){
return class_variable;
}

public void setInstanceVariable(int val){
instance_variable = val;
}

public int getInstanceVariable(){
return instance_variable;
}
}


-----------------------------------------------------------------------------------------------
Example 2.2: ApplicationClass.java

package com.pulpfreepress.jfa.chapter1;

public class ApplicationClass {

public static void main(String args[]){
SampleClass sc = new SampleClass();
System.out.println(SampleClass.CONST_VAL);
System.out.println(SampleClass.getClassVariable());
System.out.println(sc.getInstanceVariable());
SampleClass.setClassVariable(3);
sc.setInstanceVariable(4);
System.out.println(SampleClass.getClassVariable());
System.out.println(sc.getInstanceVariable());

System.out.println(sc.getClassVariable());
}
}
-----------------------------------------------------------------------------------------------

I still got compile errors as such:
[parsing started src\com\pulpfreepress\jfa\chapter1\ApplicationClass.java]
src\com\pulpfreepress\jfa\chapter1\ApplicationClass.java:1: 'class' or 'interface' expected
package com.pulpfreepress.jfa.chapter1;
^
src\com\pulpfreepress\jfa\chapter1\ApplicationClass.java:1: illegal character: \187
package com.pulpfreepress.jfa.chapter1;
^
src\com\pulpfreepress\jfa\chapter1\ApplicationClass.java:1: illegal character: \191
package com.pulpfreepress.jfa.chapter1;
^
[parsing completed 62ms]
[parsing started src\com\pulpfreepress\jfa\chapter1\SampleClass.java]
src\com\pulpfreepress\jfa\chapter1\SampleClass.java:1: 'class' or 'interface' expected
package com.pulpfreepress.jfa.chapter1;
^
src\com\pulpfreepress\jfa\chapter1\SampleClass.java:1: illegal character: \187
package com.pulpfreepress.jfa.chapter1;
^
src\com\pulpfreepress\jfa\chapter1\SampleClass.java:1: illegal character: \191
package com.pulpfreepress.jfa.chapter1;
^
src\com\pulpfreepress\jfa\chapter1\SampleClass.java:2: 'class' or 'interface' expected
import java.util.*;
^
[parsing completed 31ms]
[total 93ms]
7 errors

After hours and several Google searches on 'class' or 'interface' expected, checking syntax, etc with no success, I wondered what the hell this: was.

Turns out, in my efforts to create files that would be usable in Unix and Windows I encoded my text files as UTF-8. Upon changing them back to Ansii they compiled without error.

Time to read up on Unicode.

Labels: ,

Monday, September 18, 2006

Path / CLASSPATH Changes

After making changes to the System Path /CLASSPATH environment variables in Windows, close existing command prompts and open a new one for the changes to be reflected.
No comment on how long it took me to figure this out.

Labels: ,

Thursday, February 16, 2006

VBScript Calculate Working Business Days

After spending an hour searching for this I finally dsecided to just do it myself. It's not that there weren't Any solutions available, just none that did exactly what I wanted to the degree I wanted. And this code is Far from perfect, but does what I need now. The title of this post consists of the keywords I used to find something like what I came up with, based on Many Similar Examples, mostly in SQL. However, I don't want to implement this in SQL until I understand any potential performance hits.

You'll notice there's no date validation. I know, I suck. Although refined a bit I can tell just by looking this could be a lot better, but I've learned the hard way, a less than optimal temporary solution is better than none at all as long as it remains a temporary solution... which means I'll have to have an imporved version in a follow up post :p

'==================================================
'WRKDAYSBETWEEN
'
'Calculates number of working days (Mon-Fri) between 2 dates
'
'==================================================
Function WrkDaysBetween(dtStart, dtEnd)

totalDays = DateDiff("D", dtStart, dtEnd)
totalWeeks = DateDiff("W", dtStart, dtEnd)

'COUNT DAYS IN FIRST WEEK -WEEKENDS
Select Case WeekDay(dtStart)
Case vbMonday
daysFirstWeek = 5
Case vbTuesday
daysFirstWeek = 4
Case vbWednesday
daysFirstWeek = 3
Case vbThursday
daysFirstWeek = 2
Case vbFriday
daysFirstWeek = 1
Case vbSaturday
daysFirstWeek = 0
Case vbSunday
daysFirstWeek = 0
End Select

'COUNT DAYS IN END WEEK -WEEKENDS
Select Case WeekDay(dtEnd)
Case vbSaturday
daysLastWeek = 0
Case vbSunday
daysLastWeek = 0
Case vbMonday
daysLastWeek = 0
Case vbTuesday
daysLastWeek = 1
Case vbWednesday
daysLastWeek = 2
Case vbThursday
daysLastWeek = 3
Case vbFriday
daysLastWeek = 4
End Select

modDays = totalDays Mod 7

'GET DAYS OUTSIDE OF WEEKS
if modDays < daysFirstWeek + daysLastWeek then
oddDays = modDays
else
oddDays = daysFirstWeek + daysLastWeek
end if 'modDays < daysFirstWeek + daysLastWeek


if totalDays < daysFirstWeek then
wrkDays = totalDays + (totalWeeks * 5)
else
wrkDays = oddDays + (totalWeeks * 5)
end if 'totalDays < daysFirstWeek

WrkDaysBetween = wrkDays

End Function
'==================================================

Addendum: This link was NOT there yesterday. Damn ever changing web...

Labels:

Tuesday, February 14, 2006

I LOVE O'Reilly Safari Bookshelf

I read a lot of technical books. Unfortunately, I buy even more. Whether for reference or ramp up, I get several books on any given subject and consume until I find what I need or feel "comfortable" with the topic at hand. This has lead to a lot of wasted paper, not to mention the occasional frustration of newer editions coming out a month or two after I finally pick up a title (which means I hadn't even started reading it yet).

Although I frequent several publishers, I've been a fan of O'Reilly books for a while. Yes the I think the animals are cool. Cooler still, is the regularly reinforced reputation for solid content.

I don't remember how I was originally introduced to the SB, but it seemed too good to be true. I spend a lot of time searching the internet for relevant and recent technical info. There's a lot of smart people out there who are willing to share. (I hope to be worthy of becoming one of them some day.) This site... no, this Service advertized the ability to search published books. The number of times I wanted to do this flashed before my eyes. I tried it "Free for 14 days". I was hooked in the first couple hours.

I could go into detail about the sheer number of books available or the incredible range of information available. Instead, I'll give the current count (3616) list the categories (mmm cut & paste *homeresque gargle*):

Applied Sciences
Artificial Intelligence
Business
Certification
Computer Science
Databases
Desktop Applications
Desktop Publishing
E-Business
E-Commerce
Enterprise Computing
Graphics
Hardware
Human-Computer Interaction
Internet/Online
IT Management
Markup Languages
Multimedia
Networking
Operating Systems
Programming
Security
Software Engineering

The reason I truly love the Safari Bookshelf is because of how it's transformed how I consume information. As a web developer, I read a LOT of web pages. I'm a little afraid to think how many. What's never occured to me is the ease at which I can intake massive amounts of info from the web. How is that different any other source? When I pick up a technical book (which with most is a mini-workout in and of itself), I read as much as I can in a sitting, put in a bookmark and come back to it when:
1) I need info from that book.
2) I happen to have that book and time to read
3) I happen upon that book and decide to pick up again
I don't necessarily complete a chapter or a section of a chapter before stopping and a bookmark means I stopped at some point within two pages. I'm also limited to the number of books I can afford or want to carry around.

Enter the Safari Bookshelf. As long as I have an internet connection (what kind of web developer would I be if I didn't have access everywhere :p), I have access to 28 books right now. My queue tops out at 30. The amazing thing is ,depending on my focus, I'm actually reading all of them. I'm reading some from cover to cover and others for reference. In amount of high quality info on hand, I fond the contents noticably more readable. I need this next statement to stand out as it is a pivotal point...

Unlike ebooks, which are electronic, page for page, reproductions of their printed counterparts, books on safari have their own unique layout thats broken into logical sections without pritnted material constraints.

Each topic of a book is given it's own page. Some topics are a paragraph. Some topics are an entire chapter. Different books break down in different ways, but whats consistent is that when you get to the bottom of a page, you've consumed a packaged chunk of logic that feels much closer to what the author intended. It's like the difference between a normal conversation and having to pause for a minute each time the combined number of words reached a certain limit. Although, not show stopping, when that restriction is gone, you feel the difference.

Using FreeMind (a free mind mapping software) I've taken to logging the books I've gone through as there's no history I can find. An export of this mind map is avaiable here.

Despite my love of the service, I recognize some room for improvement. Their download options make NO sense to me. After the first couple of months of unused tokens I decide to used them on Eclipse Distilled. 3 months of tokens (the most you can have at once) got me some of the book. Once in PDF format I realized I'd moved backwards to the limitations of printed material and not even a complete work. Soon after I changed subscriptions to remove tokens. Haven't missed them once.

Labels: , , ,