求助xml文件的问题
string file = HttpContext.Current.Server.MapPath("~/file/count.xml");
public int add(string sname,string spass,string dt)
{
HyperLink1.NavigateUrl = file;
int cid=0;
try{
XmlDocument xdl=new XmlDocument();
xdl.Load(file);
XmlNode node=xdl.SelectSingleNode("/counts");
if(node!=null)
{
XmlNode last=node.LastChild;
cid=Int32.Parse(last.Attributes["id"].Value)+1;
}
else
{
cid=1;
}
XmlNode child=xdl.CreateNode(XmlNodeType.Element,"count",null);
addattribute(xdl,child,"id",cid.ToString());
addattribute(xdl, child, "name", sname);
addattribute(xdl,child,"passWord",spass);
addattribute(xdl, child, "dateTime", dt);
node.AppendChild(child);
xdl.Save(file);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return cid;
}
private void addattribute(XmlDocument xmldoc, XmlNode parent, string sname, string value)
{
XmlAttribute attribute = xmldoc.CreateAttribute(sname, null);
attribute.Value = value;
parent.Attributes.Append(attribute);
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
add(TextBox1.Text, TextBox2.Text, System.DateTime.Now.ToString());
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
可是 提交总是说无法将对象引入到所制订的实例?
[解决办法]
Object reference not set to an instance of an object.
是这个错误吗?
代码:
cid=Int32.Parse(last.Attributes["id"].Value)+1;
[解决办法]
把具体的错误是哪一条语句产生的,描述一下