Re: WPF/LinqToSql/DataGrid

Tech-Archive recommends: Fix windows errors by optimizing your registry



Peter Duniho wrote:
On Wed, 06 May 2009 14:12:12 -0700, Bill McCormick
<wpmccormick@xxxxxxxxxxxxxxxx> wrote:

Hello,

Selecting certain rows of data from my WPF datagrid (bound to a LinqToSQL datasource) are generating exceptions that I'm not sure how to handle.

It's a FormatException with message: String must be exactly one character long, but I can't tell what it is about these records that is causing the problem.

The only info I know how to get is the stack trace (below) and it's not helping me.

Hint: don't put important information in your post below your signature.
Many news readers simply hide the signature, others format it with less
emphasis than the rest of the post, and either way the important
information is difficult or impossible to access.

Right. Thanks.

As for the question, it's not clear to me what the question actually is.
The exception seems pretty clear to me: you're trying to convert a string,
but the conversion requires that the string be only one character long.

1st sentence: "... generating exceptions that I'm not sure how to handle."


In this particular case, it appears that the conversion is to the
System.Char type, which makes perfect sense. What would the conversion do
if you tried to convert something longer than one character to System.Char?

The fix is to stop trying to squeeze multiple characters into a single
character. Whether this means you need to fix the data, so that it's only
one character long, or you need to fix the destination, so that it has the
type System.String instead of System.Char, I can't say. You didn't post a
concise-but-complete code sample that reliably demonstrates the problem.
But I think it's likely the solution will be along the lines of one or the
other of those approaches.

I'd gladly post a complete and concise code sample if I knew what that would be; I wouldn't want to just post the whole solution. But if you could suggest something specific, I'd gladly post it.

So I have 2 questions:

1. How do I handle these exceptions? Where in code should it be done? In the code behind the XAML for the UserControl that the DataGrid is on? Or in the App.xaml.cs? Maybe the Main.xaml.cs? Or maybe the designer.cs module. I understand only partially what the problem and how to fix it for lack of information.

2. As you say, the "fix is to stop trying to squeeze multiple characters into a single character." I saw that, but without more information from the IDE, I can't tell which field I'm trying to *squeeze* data into. So where do I look to get the information I need?


Thanks,


Bill McCormick
--
MSDN Subscriber
.



Relevant Pages

  • Re: WPF/LinqToSql/DataGrid
    ... Selecting certain rows of data from my WPF datagrid are generating exceptions that I'm not sure how to handle. ... String must be exactly one character long, but I can't tell what it is about these records that is causing the problem. ... The fix is to stop trying to squeeze multiple characters into a single ... concise-but-complete code sample that reliably demonstrates the problem. ...
    (microsoft.public.dotnet.languages.csharp)
  • Subterrane v0.194 Alpha Released
    ... system, a character sheet, a ton of new spells, new monsters, item ... Added a character sheet that displays your character's ... Fix: Fixed a bug in the encumbrance calculation and status display ...
    (rec.games.roguelike.announce)
  • Re: Small Correction to K&R Exercise 1-22 Solution on CLC-Wiki
    ... Your fix looks correct to me at least. ... I don't think that overwriting the n-th character with a ... int t,len; ... ** to the foldarea with a newline. ...
    (comp.lang.c)
  • Re: Small Correction to K&R Exercise 1-22 Solution on CLC-Wiki
    ... My fix is now reflected at the above address. ... Your code answering the challenge includes the obvious fix for this bug - ... lines after the last non-blank character that occurs before the n-th ... reasoning behind this design choice was that I didn't want to go through ...
    (comp.lang.c)
  • Re: -7DRL- SewerJacks (finally)
    ... My character had just managed to take ... And then the game crashed on me. ... Its first on my fix list. ... you can lose allies trying to bring more than one down stairs. ...
    (rec.games.roguelike.development)