I'm not sure how I could do anything else. It tries to cast the XML Node
value to a string and if the cast fails, it throws an Invalid Cast
Exception, then sends out the message: The value for column <columnName>
in table <tableName> is DBNull.
It should pass the DBNull along so I can test for it, but it never gets
that far. You can't modify your code when you don't even have access to
the variable.
Do you think there's a way to catch the exception? Even if there is,
isn't that bad practice to use an exception to determine a decision
branch in the code?
--
Regards,
Fred Chateau
http://hotelmotelnow.com
--
Regards,
Fred Chateau
http://hotelmotelnow.com
in message Fred,
Well, I wouldn't do that. What I was recommending was to determine
what the value that was being returned was through the debugger in your
program, and then using that knowledge to change the code.
Generally, I wouldn't change the designer code, because it will not
respect your changes if you make changes through the designer.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Well, I can't believe I found it but I did. I had to edit the code
generated by XSD.
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public string Chain_ID {
get {
try {
if (!Convert.IsDBNull(this[this.tableIdentity.Chain_IDColumn]))
<-- Added code
return ((string) (this[this.tableIdentity.Chain_IDColumn]));
else
return "0"; <-- Added code
}
catch (System.InvalidCastException e) {
throw new System.Data.StrongTypingException("The value for column
\'Chain_ID\' in table \'Identity\' is DBNull.", e);
}
}
set {
this[this.tableIdentity.Chain_IDColumn] = value;
}
}
--
Regards,
Fred Chateau
http://hotelmotelnow.com
"Nicholas Paldino [.NET/C# MVP]" <
[email protected]>
wrote in message Fred,
Have you set a point in the debugger and looked at what the value
of:
dataSet.Identity[x].Chain_ID
Actually is?
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
I can't seem to find a test for DBNulls. Whatever I try doesn't work.
for (int x = 0; x < dataSet.Identity.Rows.Count; x++)
{
DataRow dataRow = dataSet.Tables["POI_Entity"].NewRow();
if (!dataSet.Identity[x].Chain_ID.Equals(DBNull.Value))
dataRow["Chain_Id"] = dataSet.Identity[x].Chain_ID;
else
dataRow["Chain_Id"] = 0;
dataSet.Tables["POI_Entity"].Rows.Add(dataRow);
}
I've also tried
(!Convert.IsDBNull(dataSet.Identity[x].Chain_ID)
That doesn't work either.
--
Regards,
Fred Chateau
http://hotelmotelnow.com