Some code a converter did that I don't understand.
Hello everyone. I ran some vb code in an online vb to c# converter app and some of the code that it generated I can't get it to work. I get a red squiggly line under the word "Information" and the message is "The name "Information" does not exist in the current context. So I get rid of the word "Information". So now IsDBNull is underlined with the red squiggly line and the message now reads "The name 'IsDBNull' does not exist in the current context". This code is in a class source file which is part of a class library vs2008. Anyone able to give me a hand with this?
Code:
myPopulationGroupsTb = new PopulationGroupsTb();
var _with2 = myPopulationGroupsTb;
_with2.ID = (Information.IsDBNull(myReader["ID"]) ? 0 : myReader["ID"]);
_with2.PopulationGroup = (Information.IsDBNull(myReader["PopulationGroup"]) ? string.Empty : myReader["PopulationGroup"]);
_with2.PopulationGroupLabel = (Information.IsDBNull(myReader["PopulationGroupLabel"]) ? string.Empty : myReader["PopulationGroupLabel"]);
_with2.MinPopulation = (Information.IsDBNull(myReader["MinPopulation"]) ? 0 : myReader["MinPopulation"]);
_with2.MaxPopulation = (Information.IsDBNull(myReader["MaxPopulation"]) ? 0 : myReader["MaxPopulation"]);
Re: Some code a converter did that I don't understand.
That converter produces code with horrible naming conventions. If the reader is a SqlDataReader, then just use its IsDbNull method.
Re: Some code a converter did that I don't understand.
The converter should have changed "Information.IsDBNull" to "System.Convert.IsDBNull".