Insert Update Delete With XML file in c#
DataSet ds=new DataSet()
1) TO Insert To XML FIle.
ds.ReadXml(@"D:\ResumeSettings\Email.xml");
for (int i = 0; i < col.Count; i++)
{
ds.Tables[0].Rows.Add(col[i].ToString(), "1");
}
ds.WriteXml(@"D:\ResumeSettings\Email.xml");
2) Delete From XML File.
ds.ReadXml(@"D:\ResumeSettings\Email.xml");
if (ds.Tables[0].Rows.Count > 0)
{
for (int d = 0; d < ds.Tables[0].Rows.Count; d++)
{
ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[d]);
}
}
ds.WriteXml(@"D:\ResumeSettings\Email.xml");
3) TO Update XML FIle.
ds.ReadXml(@"D:\ResumeSettings\SettingsData.XML");
DataRow[] dr = ds.Tables[0].Select("foldername= '" + FolderName.Trim().ToString() + "'");
foreach (DataRow ChangeRow in dr)
{
ChangeRow.BeginEdit();
ChangeRow[1] = "1";
ChangeRow.EndEdit();
}
ds.GetChanges(DataRowState.Modified);
ds.WriteXml(@"D:\ResumeSettings\SettingsData.XML");
Make the necessary changes as per ur xml files.
No comments:
Post a Comment