When developing a system, it is common to get its description by code, for example, to get an error message from an error number.
These error messages can be stored in an XML data file and read through a DataSet object.
The following functions are read:
public string geterror (int errorid)
{
When you make an error display, you can put the text description of the error number into an XML
File. This is a common way to support multiple languages.
This example extracts the data from an XML file and obtains an error description for the specified ID number.
string filename;
Datarow[] Dr;
The file path can also be configured in the Web. config file
Filename=this. Request.physicalapplicationpath + "/errorinfo.xml";
Create a DataSet object
DataSet ds=new DataSet ("ErrorInfo");
Reading an XML file
Ds. READXML (filename);
To find
Dr=ds. Tables[0]. Select ("code=" + errorid.tostring ());
if (Dr. Length==1)
{
return dr[0]["Description"]. ToString ();
}
Else
{
Return "";
}
}
The following is an example of an XML file:
<errorinfo>
<erroritem>
<code>200</code>
<Description> successful </description>
</erroritem>
<erroritem>
<code>700</code>
<Description> incorrect password </description>
</ Erroritem>
<erroritem>
<code>800</code>
< description> account Invalid </description>
</erroritem>
</errorinfo>