SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Training
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
SQL Azure
Developer
General DBA
ASP.NET / ADO.NET
SQL Azure

USEFUL SITES :

ASP.NET Tutorials
Windows and SQL Azure Tutorials
Cloud Hosting Magazine
SharePoint Tutorials
Windows Server Help

Write for Us

Share your SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server

More     
 
Latest FAQ's

Add Node to A SQL Server failover Cluster failed with invalid ...
SQL Server Destination remote server error
Setting Up Data And Log Files For SQL Server
Will Check Constraints Improve Database Performance?

More     
   
Latest Software Reviews

dbForge Review
Spotlight on ApexSQL Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Data Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Doc 2008

More     

articles >> asp.net / ado.net >> DataSets and XML – A Perfect Combination ...

DataSets and XML – A Perfect Combination

By : Joydip Kanjilal
Jan 22, 2007

Page 2 / 3


Working with DataSet and XML

This section discusses how we can perform the CRUD operations using DataSet and XML as the database to store the data.


Storing a DataSet instance to a XML File

The code sample below demonstrates how we can store data from a DataSet object directly to a disk file in XML format. The resultant XML document has been named as employee.xml

string connectionString = …; //Some connection string
SqlConnection sqlConnection =
new SqlConnection(connectionString);
SqlDataAdapter sqlDataAdapter =
new SqlDataAdapter(
"select name,id,joindate from employee", sqlConnection);
sqlConnection.Open();
DataSet dataSet = new DataSet();
sqlDataAdapter.Fill(dataSet);
dataSet.WriteXmlSchema(Server.MapPath("employee.xml"));
dataSet.WriteXml(Server.MapPath("employee.xml"));

Read Data from a XML file using a DataSet

The code that follows illustrates how we can search data from a XML document using a DataSet. The name of the method used is SearchData that returns a signed integer value of -1 if the record being searched (employee ID in our case is the key on which the search operation is being performed) is not found.


private int SearchData(int empID)
{
string filePath = …; //Some path indicating where the xml file // is stored
DataSet dataSetEmployee = GetEmployeeDataSet(); //Retrieve the // employee DataSet instance
DataTable dataTableEmployee = dataSetEmployee.Products.Tables[0];
DataView dataViewEmployee = new DataView();
dataViewEmployee = dataTableEmployee.DefaultView;
dataViewEmployee.Sort = "Emp_ID";
int rowIndex = dataViewEmployee.Find("empID");
return rowIndex;
}

Note that once the SearchData method returns the value of the row index (a value that is not equal to -1), an employee DataSet instance can be easily populated with the data representing the particular employee identified by the unique employee ID.

Add data to a XML file using a DataSet

The code sample below illustrates how we can append data to the xml file created above using a DataSet instance.

DataSet dataSetEmployee = GetEmployeeDataSet(); // The
// GetEmployeeDataSet method populates a DataSet object with
// employee data and schema information and returns the instance
DataRow employeeRecord = dataSetEmployee.Tables[0].NewRow();
employeeRecord[0] = 1;
employeeRecord[1] = “Joydip Kanjilal”;
dataSetEmployee.Tables[0].Rows.Add(employeeRecord);
string filePath = …; //Some path where the file is stored
dataSetEmployee.WriteXml(filePath,XmlWriteMode.WriteSchema);


<< Prev Page     Next Page>>    








C# Help and Tutorials | PHP MySQL Tutorial | Sharepoint Tutorial | Azure Tutorial | Cloud Hosting Magazine | ASP.NET Tutorials | Windows Server Help | Windows Phone Pro | Silverlight Ace | Visual Studio Tutorials | Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | SQL Server Training Videos | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 2010 Jude O'Kelly. All rights reserved