ReadXML and WriteXML




public void BuildDataSetXML()
{
//sql is a placeholder variable to store the sequel statement
string sql = String.Format("SELECT TOP * FROM [CustomerInfo] WHERE CmpID={0}", CompanyID.ToString());

//fileNameWithAllData is a placeholder variable to store the name of the xml file
string fileNameWithAllData = String.Format("ReadCustomerInfoByCompanyID_{0}.xml", CompanyID.ToString());

//process the result of the sequel statement to dsAllData variable
DataSet dsAllData = ProcessDataset(CommandType.Text, sql);

//Dataset is stored in the fileNameWithAllData
dsAllData.WriteXml(fileNameWithAllData);
}


How do I WriteXML to a location that I want such as (C:\Desktop\fileName)? Right now the xml file is saving somewhere else.



public DataSet GetCustomerInfo(int CompanyID)
{
//pass in the method above
BuildDataSetXML();

//pass in the variable from the above method
string fileNameWithAllData = String.Format("ReadCustomerInfoByCompanyID_{0}.xml", CompanyID.ToString());

//Instantiate ds
DataSet ds = new DataSet();

//Read into the fileNameWithAllData
ds.ReadXml(fileNameWithAllData);

//Query the fileNameWithAllData (ReadCustomerInfoByCompanyID_{0}.xml) and only get lastName and firstName in the field
string sqlFieldSelected = String.Format("SELECT lastName, firstName FROM fileNameWithAllData");

//fileNameSelectedField is a placeholder variable to store the name of the xml file
string fileNameSelectedField = string.Format("GetName.xml").ToString();

//process the result of the sequel statement to dsSelectedData variable
DataSet dsSelectedData = ProcessDataset(CommandType.Text, sqlFieldSelected);

//write out the data from sequel to XML
ds.WriteXml(fileNameSelectedField);

return ds;
}


I want to read into(ReadXML) the XML file that was already created and want to write out(WriteXML) a new XML with selected fields(firstName and lastName). Thank you


No comments:

Post a Comment