Below Program is example for converting Entity Object into Dataset using Xmlserilizer.
Step 1 :Create a class called Book.cs
using System.Linq;
using System.Text;
public string FirstName;
public string MI;
public string LastName;
}
Step 2: Create Console application.
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Data;
class Program
{
Book objbooks;
static void Main(string[] args)
{
fnserialise();
}
objbooks.LastName = "Kumar";
objbooks.MI = "A";
serializer = new XmlSerializer(objbooks.GetType());
stream = new MemoryStream();
serializer.Serialize(stream, objbooks);
DataSet BookData = new DataSet("Books");
stream.Position = 0;
BookData.ReadXml(stream);
stream.Close();
}
}
Step 1 :Create a class called Book.cs
using System;
using System.Collections.Generic;using System.Linq;
using System.Text;
public class Book
{public string FirstName;
public string MI;
public string LastName;
}
Step 2: Create Console application.
using System;
using System.Collections.Generic;using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Data;
class Program
{
Book objbooks;
static void Main(string[] args)
{
fnserialise();
}
static void
fnserialise()
{
Book objbooks = new
Book();
objbooks.FirstName = "Ram";objbooks.LastName = "Kumar";
objbooks.MI = "A";
XmlSerializer serializer;
MemoryStream stream;serializer = new XmlSerializer(objbooks.GetType());
stream = new MemoryStream();
serializer.Serialize(stream, objbooks);
DataSet BookData = new DataSet("Books");
stream.Position = 0;
BookData.ReadXml(stream);
stream.Close();
}
}
No comments:
Post a Comment