Silicon Thumb

Since the 1980s, I've worked with computers, watched them grow, shrink, change and improve. I've worked with a lot of users and solved a lot of problems in that time too, so I thought this would be a good place to share some of the random things I've found and solved. If you have some odd problem, email me. If I can figure it out I'll post the answer here.

My Photo
Location: Mansfield, Texas, United States

I am a veteran computer geek, but I prefer the term 'Hired Gun', since that gives the (misleading) impression that I know what I'm talking about. I have worked on all sizes of system as an engineer, developer, technical support and operations, and at all levels from Operator to CIO.
I have some certifications, but what they are depends on what Microsoft is calling them this week.

If you have a question, and don't mind the answer being posted, email me here, removing the spam stopper.

Friday, December 28, 2012

Truncated Memo Fields

This one drove me crazy for three hours and I thought I would share it with you, as it demonstrates the dangers of falling for the red herring!

Observe this simple piece of code:

Dim dvStory As DataView = _ DirectCast(dsStory.Select(DataSourceSelectArguments.Empty), DataView)

For Each drvStory As DataRowView In dvStory ' Should only be one
    lblHeading.Text = drvStory("Heading").ToString()
    lblSubHeading.Text = drvStory("SubHeading").ToString()
    storyBlock.Text = drvStory("Block").ToString()

Essentially I am pulling values from an Access database and populating a webform. Everything is fine, except for the storyBlock.Text which is pulling from a memo field called Block.

When presented, the field is truncated at 255 Characters. 

"Damn .toString()!" I yelled in frustration. Obviously the toString was truncating the field and try as I might I could not find away around it. Except of course, it wasn't truncating the field. The real culprit lay in the call to Access via SQL:

<asp:AccessDataSource ID="dsStory" runat="server" DataFile="~/CompanyNews.mdb"
  SelectCommand="SELECT DISTINCT [Group], [Heading], [SubHeading], [Block], [PublishFrom] FROM [Blocks]">


There was a WHERE clause in there too which I removed for simplicity's sake.
Turns out that the 'DISTINCT' was the cause of the problems. When I asked the query to return only distinct values, Access was forced to compare the memo field against all other records, and that comparison causes truncation. By forcing uniqueness at entry level I was able to throw away that clause and now the .toString() (which was doing its job correctly all along) returns the full memo field value.

Fun way to end the year!