Truncated Memo Fields
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()
Next
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]">
</asp:AccessDataSource>
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!
0 Comments:
Post a Comment
<< Home