S
Stephen
I have the following code that is getting (or should get) the max value
from an xml file. Even though the max value should be 21, it is always
returning 9:
DataSet ds = new DataSet();
DataTable dt = new DataTable();
ds.ReadXml(Server.MapPath"~/Home/XMLMenus/MenuCategory.xml"),XmlReadMode.InferSchema);
dt = ds.Tables[0];
string selectCommand = "Max(report_category_id)";
string filterCommand = "report_category_id > 0";
int nextNum =
Convert.ToInt32((object)dt.Compute(selectCommand,string.Empty));
DataRow dr = ds.Tables[0].NewRow();
dr["report_category_id"] = nextNum + 1;
dr["report_category"] = "Test";
ds.Tables[0].Rows.Add(dr);
DataGrid1.DataSource = dt;
DataGrid1.DataBind();
here is the xml:
<NewDataSet>
<Table>
<report_category_id>1</report_category_id>
<report_category>Accounting</report_category>
</Table>
<Table>
<report_category_id>5</report_category_id>
<report_category>Company</report_category>
</Table>
<Table>
<report_category_id>21</report_category_id>
<report_category>Continuous Improvement</report_category>
</Table>
<Table>
<report_category_id>6</report_category_id>
<report_category>Customer Care</report_category>
</Table>
<Table>
<report_category_id>7</report_category_id>
<report_category>Documentation</report_category>
</Table>
<Table>
<report_category_id>8</report_category_id>
<report_category>Employee</report_category>
</Table>
<Table>
<report_category_id>9</report_category_id>
<report_category>Engineering</report_category>
</Table>
<Table>
<report_category_id>10</report_category_id>
<report_category>Test</report_category>
</Table>
I have a feeling it is treating the xml values as strings because
removing the single digit numbers whos left char is equal to or less
than the left char of the max double digit returns the right value. In
other words 3 > 21 because 3 > 2 and 21 > 2. Any suggestions?
from an xml file. Even though the max value should be 21, it is always
returning 9:
DataSet ds = new DataSet();
DataTable dt = new DataTable();
ds.ReadXml(Server.MapPath"~/Home/XMLMenus/MenuCategory.xml"),XmlReadMode.InferSchema);
dt = ds.Tables[0];
string selectCommand = "Max(report_category_id)";
string filterCommand = "report_category_id > 0";
int nextNum =
Convert.ToInt32((object)dt.Compute(selectCommand,string.Empty));
DataRow dr = ds.Tables[0].NewRow();
dr["report_category_id"] = nextNum + 1;
dr["report_category"] = "Test";
ds.Tables[0].Rows.Add(dr);
DataGrid1.DataSource = dt;
DataGrid1.DataBind();
here is the xml:
<NewDataSet>
<Table>
<report_category_id>1</report_category_id>
<report_category>Accounting</report_category>
</Table>
<Table>
<report_category_id>5</report_category_id>
<report_category>Company</report_category>
</Table>
<Table>
<report_category_id>21</report_category_id>
<report_category>Continuous Improvement</report_category>
</Table>
<Table>
<report_category_id>6</report_category_id>
<report_category>Customer Care</report_category>
</Table>
<Table>
<report_category_id>7</report_category_id>
<report_category>Documentation</report_category>
</Table>
<Table>
<report_category_id>8</report_category_id>
<report_category>Employee</report_category>
</Table>
<Table>
<report_category_id>9</report_category_id>
<report_category>Engineering</report_category>
</Table>
<Table>
<report_category_id>10</report_category_id>
<report_category>Test</report_category>
</Table>
I have a feeling it is treating the xml values as strings because
removing the single digit numbers whos left char is equal to or less
than the left char of the max double digit returns the right value. In
other words 3 > 21 because 3 > 2 and 21 > 2. Any suggestions?