Thursday, March 12, 2009

In-Memory Dataset operation (Add/Mod/Del) using C#

DataSet dstestoperation = new DataSet();
DataTable dtTestTab = new DataTable();
DataView dvTest;
private FileInfo fitest = new FileInfo(@"c:\MyXML\PicturePath.xml");
private FileInfo fitestschema = new FileInfo(@"c:\MyXML\PicturePath.xsd");

private void DeleteFromTestDataset()
{
DataRow[] dtTestTabrowcollection = (DataRow[])dtTestTab.Select("PictureEmail = '" + txtEmailid.Text + "'");
if (dtTestTabrowcollection.Length > 0)
{
foreach (DataRow myrow in dtTestTabrowcollection)
{
myrow.Delete();
}
}
getcount();
}
private void AddtoTestDataset()
{
DataRow myrow = dtTestTab.NewRow();
myrow["PictureEntryid"] = "A00";
myrow["PictureEmail"] = txtEmailid.Text;
myrow["PictureName"] = "cartoons";
myrow["PictureIcon"] = @"C:\Documents and Settings\My Documents\My Pictures\swaps_"+DateTime.Now.Minute.ToString() + ".jpg";
myrow["PicturePhone"] = "+111-111-1111";
dtTestTab.Rows.Add(myrow);
getcount();
}
private void ModifyTestDataset()
{
DataRow[] dtTestTabrowcollection = (DataRow[])dtTestTab.Select("PictureEmail = '" + txtEmailid.Text + "'");
if (dtTestTabrowcollection.Length > 0)
{
foreach (DataRow myrow in dtTestTabrowcollection)
{
myrow["PictureName"] = "MyPictures";
}
}
getcount();
}
private int testDuplicate()
{
DataRow[] dtTestTabrowcollection = (DataRow[])dtTestTab.Select("Pictureid = '" + txtid.Text + "'");
return (dtTestTabrowcollection.Length - 1);
}
private int TitleCase()
{
System.Globalization.CultureInfo mycultureinfo = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Globalization.TextInfo mytextinfo = mycultureinfo.TextInfo;
txtEmailid.Text = mytextinfo.ToTitleCase(txtEmailid.Text);
}


private void btnSave_Click(object sender, EventArgs e)
{
dtTestTab.AcceptChanges();
dstestoperation.WriteXml(fitest.FullName, XmlWriteMode.IgnoreSchema);
btnSave.Enabled = false;
}

No comments:

Post a Comment