當前位置: 首頁>>代碼示例>>C#>>正文


C# DataTable.WriteXml方法代碼示例

本文整理匯總了C#中System.Data.DataTable.WriteXml方法的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.WriteXml方法的具體用法?C# DataTable.WriteXml怎麽用?C# DataTable.WriteXml使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Data.DataTable的用法示例。


在下文中一共展示了DataTable.WriteXml方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: exportAccountData

        /// <summary>
        /// Function to export all the Account data to the XML File
        /// </summary>
        private static void exportAccountData()
        {
            DataTable AccountDB = new DataTable();
            AccountDB.TableName = "Account Database";
            AccountDB.Columns.Add("AccountID");
            AccountDB.Columns.Add("Balance");
            AccountDB.Columns.Add("Type");
            AccountDB.Columns.Add("ClientID");
            AccountDB.Columns.Add("Interest");
            AccountDB.Columns.Add("Limit");

            foreach (KeyValuePair<string, Account> entry in Program.AccountData)
            {
                DataRow row = AccountDB.NewRow();
                row["AccountID"] = entry.Value.ACCOUNTID;
                row["Balance"] = entry.Value.BALANCE;
                row["Type"] = entry.Value.ACCOUNTTYPE;
                row["ClientID"] = entry.Value.CLIENTID;
                if (entry.Value.ACCOUNTTYPE=="Interest")
                {
                    AccountInterest temp1 = (AccountInterest)entry.Value;
                    row["Interest"] = temp1.INTEREST;
                    row["Limit"] = null;
                }
                else
                {
                    AccountNoInterest temp2 = (AccountNoInterest)entry.Value;
                    row["Limit"] = temp2.LIMIT;
                    row["Interest"] = null;
                }
                AccountDB.Rows.Add(row);
            }
            AccountDB.WriteXml("myAccount.xml");
        }
開發者ID:HgM3rk,項目名稱:VirtualBankingSystem-School-,代碼行數:37,代碼來源:xmlData.cs

示例2: ConvertAltmanDataTableToXml

		private static string ConvertAltmanDataTableToXml(DataTable dt)
		{
			MemoryStream stream = null;
			XmlTextWriter writer = null;
			try
			{
				stream = new MemoryStream();
				writer = new XmlTextWriter(stream, Encoding.Default);
				writer.Formatting = Formatting.Indented; 
				dt.WriteXml(writer);
				var count = (int)stream.Length;
				var arr = new byte[count];
				stream.Seek(0, SeekOrigin.Begin);
				stream.Read(arr, 0, count);
				return new UTF8Encoding().GetString(arr);
			}
			catch
			{
				return String.Empty;
			}
			finally
			{
				if (writer != null)
					writer.Close();
			}
		}
開發者ID:kevins1022,項目名稱:Altman,代碼行數:26,代碼來源:Export.cs

示例3: GetDataTableXml

 protected string GetDataTableXml(DataTable dt)
 {
     dt.TableName = "must have name for xml...";
     var writer = new StringWriter();
     dt.WriteXml(writer);
     return writer.ToString();
 }
開發者ID:jlarsson,項目名稱:Kiwi.Json,代碼行數:7,代碼來源:DataTableConverterFixtureBase.cs

示例4: ToDataTableXmlString

        ///// <summary>
        ///// 序列化物件
        ///// </summary>
        ///// <typeparam name="T"></typeparam>
        ///// <param name="value"></param>
        ///// <returns></returns>
        //public string ObjectToString<T>(T value)
        //{
        //    XmlSerializer ser = new XmlSerializer(value.GetType());
        //    MemoryStream stream = new MemoryStream();
        //    ser.Serialize(stream, value);
        //    stream.Position = 0;
        //    StreamReader reader = new StreamReader(stream);
        //    string result = reader.ReadToEnd();
        //    stream.Dispose();
        //    reader.Dispose();
        //    return result;

        //}

        public string ToDataTableXmlString(IEnumerable value)
        {
            var type = value.GetType().GetGenericArguments()[0];
            DataTable dataTable = new DataTable(type.Name);
            PropertyInfo[] Props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo prop in Props)
            {
                dataTable.Columns.Add(prop.Name);
            }
            foreach (object item in value)
            {
                var values = new object[Props.Length];
                for (int i = 0; i < Props.Length; i++)
                {
                    values[i] = Props[i].GetValue(item, null);
                }
                dataTable.Rows.Add(values);
            }

            using (var memoryStream = new MemoryStream())
            {
                dataTable.WriteXml(memoryStream);
                memoryStream.Position = 0;
                using (var reader = new StreamReader(memoryStream))
                {
                    return reader.ReadToEnd();
                }
            }

        }
開發者ID:kimx,項目名稱:KFramework.DebuggerVisualizers,代碼行數:50,代碼來源:ListVisualizerObjectSource.cs

示例5: Main

        static void Main(string[] args)
        {
            Console.WriteLine("program start!!");
               // ClinetsInfoParser.Parse();
               var tbl=new DataTable();
            tbl.TableName = "custom";
            tbl.Columns.Add("Name");
            tbl.Columns.Add("Producer");
            tbl.Columns.Add("Trash");
            tbl.Columns.Add("Expires");
            tbl.Columns.Add("Quantity");
            tbl.Columns.Add("Trash2");
            tbl.Columns.Add("Division");

            for (int i = 0; i < 15; i++)
                tbl.Rows.Add("Name" + i.ToString(), "Producer" + i.ToString(), i.ToString(), DateTime.Now.ToShortDateString(),
                             i.ToString(),i.ToString(), "Division" + i.ToString());
            var stream=new MemoryStream();
            tbl.WriteXml(stream,XmlWriteMode.WriteSchema);
               var data= Packer.Pack(stream);
               var result = new ConcurrentBag<byte[]>();
            result.Add(data);
            result.ToQueryResult();

                Console.ReadKey();
        }
開發者ID:cutthenblood,項目名稱:WCFcln,代碼行數:26,代碼來源:Program.cs

示例6: AddTemplateToXML

 private void AddTemplateToXML(string nm)
 {
     string path = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + @"\templates.xml";
     DataTable dt = new DataTable("TemplateTable");
     dt.Columns.Add("TemplateName");
     DataRow dr;
     if (lstTemplate.Items.Count > 0)
     {
         try
         {
             for (int b = 0; b < lstTemplate.Items.Count; b++)
             {
                 dr = dt.NewRow();
                 dr[0] = lstTemplate.Items[b].ToString();
                 dt.Rows.Add(dr);
             }
             if (File.Exists(path))
                 File.Delete(path);
             dt.WriteXml(path);
             MessageBox.Show("Template successfully inserted.", "CSR Assistant");
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "CSR Assistant");
         }
     }
 }
開發者ID:tridipkolkata,項目名稱:SampleRepo,代碼行數:27,代碼來源:frmCallAssistant.cs

示例7: ToXmlVfp

        public void ToXmlVfp(string path)
        {
            DataTable dt = new DataTable();
            dt.TableName = "Tabla1";

            DataColumn campo1 = new DataColumn();
            campo1.DataType = typeof(string);
            campo1.MaxLength = 20;
            campo1.ColumnName = "Cae";

            DataColumn campo2 = new DataColumn();
            campo2.DataType = typeof(string);
            campo2.MaxLength = 500;
            campo2.ColumnName = "Problema";

            dt.Columns.Add(campo1);
            dt.Columns.Add(campo2);

            foreach (string mensaje in this.Problema)
            {
                DataRow registro1 = dt.NewRow();
                registro1[0] = this.Cae;
                registro1[1] = mensaje;
                dt.Rows.Add(registro1);
            }

            dt.WriteXml(path);
        }
開發者ID:GonzaloFernandoA,項目名稱:FacturacionElectronica,代碼行數:28,代碼來源:Respuesta.cs

示例8: SaveResultsToXml

        private static void SaveResultsToXml(
			string fileName,
			DataTable results
		)
        {
            results.WriteXml(fileName);
        }
開發者ID:reid15,項目名稱:DataViewer,代碼行數:7,代碼來源:ExportData.cs

示例9: GetDeliveries

 internal static string GetDeliveries()
 {
     sql = "SELECT " +
             "deliveries.id AS delivery_id, purchases.id AS purchase_id, purchases.po_number, deliveries.delivery_date, supplier_id, name AS supplier_name, " +
             "lookup_status.description AS status, lookup_status2.description AS completion_status " +
         "FROM deliveries " +
         "JOIN purchases ON purchases.id = deliveries.purchase_id " +
         "JOIN suppliers ON suppliers.id = supplier_id " +
         "JOIN lookup_status ON lookup_status.id = deliveries.status " +
         "JOIN lookup_status AS lookup_status2 ON lookup_status2.id = deliveries.completion_status " +
         "WHERE lookup_status2.description != 'Complete' ";
     dt = new DataTable();
     dt = Database.Query(sql);
     if (dt != null)
     {
         if (dt.Rows[0].ItemArray[0].ToString() == "-1")
         {
             result = dt.Rows[0].ItemArray[1].ToString();
         }
         else
         {
             StringWriter sw = new StringWriter();
             dt.WriteXml(sw);
             result = sw.ToString();
         }
     }
     else
     {
         result = Functions.FormatReturn(0, "No items found");
     }
     return result;
 }
開發者ID:kingpauloaquino,項目名稱:CERP-WS,代碼行數:32,代碼來源:Queries.cs

示例10: ConvertBetweenDataTableToXML

 public string ConvertBetweenDataTableToXML(DataTable dtNeedCoveret)
 {
     System.IO.TextWriter tw = new System.IO.StringWriter();
     //if TableName is empty, WriteXml() will throw Exception.
     dtNeedCoveret.TableName = dtNeedCoveret.TableName.Length == 0 ? "Table" : dtNeedCoveret.TableName;
     dtNeedCoveret.WriteXml(tw);
     dtNeedCoveret.WriteXmlSchema(tw);
     return tw.ToString();
 }
開發者ID:ChiangHanLung,項目名稱:PIC_VDS,代碼行數:9,代碼來源:STMCommon.cs

示例11: CreateBackUp

 public static void CreateBackUp(DataTable dt)
 {
     try
     {
         //dt.AcceptChanges();
         dt.WriteXml(BackUpFileName);
     }
     catch(Exception)
     {}
 }
開發者ID:rehman922,項目名稱:VIRETAIL,代碼行數:10,代碼來源:Functions.cs

示例12: Main

        static void Main(string[] args)
        {
     // Создание Таблицы DataTable с именем "Cars"
            DataTable tablCars = new DataTable("Cars");
            // Создание столбцов
            DataColumn carsId = new DataColumn("Id", typeof(int));
            DataColumn carsName = new DataColumn("Name", typeof(string));
            DataColumn carsCountry = new DataColumn("Country", typeof(string));
            DataColumn carsPrice = new DataColumn("Price", typeof(double));
            tablCars.Columns.AddRange(new DataColumn[] { carsId, carsName, carsCountry, carsPrice });
            // Создание строки с данными 
            DataRow newRow1 = tablCars.NewRow();
            newRow1["Name"] = "BMW"; newRow1["Country"] = "Germany";
            newRow1["Price"] = "50000";
            tablCars.Rows.Add(newRow1);

            DataRow newRow2 = tablCars.NewRow();
            newRow2["Name"] = "Audi"; newRow2["Country"] = "Germany";
            newRow2["Price"] = "37500";
            tablCars.Rows.Add(newRow2);

            // Сохранить ТАБЛИЦЫ  tablCars  в виде XML
            tablCars.WriteXml("Cars.xml");
            tablCars.WriteXmlSchema("CarsSchema.xsd");
         

      // Создание Таблицы DataTable с именем "Drivers"
            DataTable tablDrivers = new DataTable("Drivers");
            // Создание столбцов
            DataColumn drId = new DataColumn("Id", typeof(int));
            DataColumn drName = new DataColumn("Name", typeof(string));
            DataColumn drAge = new DataColumn("Age", typeof(string));
            tablDrivers.Columns.AddRange(new DataColumn[] { drId, drName, drAge });
            // Создание строки с данными 
            DataRow newRow3 = tablDrivers.NewRow();
            newRow3["Name"] = "Ivan"; newRow3["Age"] = "33";
            tablDrivers.Rows.Add(newRow3);

            DataSet dataSet = new DataSet("AutoPark");
            dataSet.Tables.AddRange(new DataTable[] { tablCars, tablDrivers});


            // Сохранить DATASET  в виде XML
            dataSet.WriteXmlSchema("AutoParkSchema.xsd");
            dataSet.WriteXml("AutoPark.xml");
            
            
            // Очистить DataSet.
            dataSet.Clear();

            Console.WriteLine("XML успешно сформированы!");

            Console.ReadKey();

        }
開發者ID:Saroko-dnd,項目名稱:My_DZ,代碼行數:55,代碼來源:Program.cs

示例13: Write

        public string Write(TableName tname, DataTable dt)
        {
            string file = getDataFileName(tname);
            using (var writer = NewStreamWriter(file))
            {
                dt.TableName = tname.Name;
                dt.DataSet.DataSetName = tname.DatabaseName.Name;
                dt.WriteXml(writer, XmlWriteMode.WriteSchema);
            }

            return file;
        }
開發者ID:fjiang2,項目名稱:sqlcon,代碼行數:12,代碼來源:XmlDbFile.cs

示例14: CreateCorrespondingXmlWhenNotExist

 public static void CreateCorrespondingXmlWhenNotExist()
 {
     if (!File.Exists(xmlPath))
     {
         var dtTableName = new DataTable();
         dtTableName.Columns.Add("OriName");
         dtTableName.Columns.Add("PascalName");
         dtTableName.TableName = "dt";
         dtTableName.Rows.Add(new[] { "1", "1" });
         dtTableName.WriteXml(xmlPath);
     }
 }
開發者ID:Raman0716,項目名稱:MyCodeGenerate,代碼行數:12,代碼來源:XmlControl.cs

示例15: CsvToXmlConvert

        /*
          Example Use
          string[] fieldNames = {
                               "Id",
                               "Name",
                               "Age"
                            };
                            CsvToXmlConvert("c:\\temp\\example.txt", "TempTable", ";", "c:\\temp\\example.xml", fieldNames);*/
        /// <summary>
        /// </summary>
        /// <param name="inputFile"></param>
        /// <param name="dataName"></param>
        /// <param name="separator"></param>
        /// <param name="outputFile"></param>
        /// <param name="fieldnames"></param>
        public static void CsvToXmlConvert(
            string inputFile,
            string dataName,
            char separator,
            string outputFile,
            string[] fieldnames = null)
        {
            var dt = new DataTable(dataName);
            bool firstRow = true;

            using (var sr = new StreamReader(inputFile))
            {
                while (!(sr.EndOfStream))
                {
                    string readLine = sr.ReadLine();
                    if (readLine == null)
                    {
                        continue;
                    }
                    string[] fields = readLine.Split(separator);
                    IEnumerable<string> e = from s in fields
                                            select s;
                    int c = e.Count();
                    if (firstRow)
                    {
                        for (int ii = 0;
                             ii <= c - 1;
                             ii++)
                        {
                            string fName = "";
                            if ((fieldnames == null))
                            {
                                fName = "Field" + ii.ToString("000");
                            }
                            else
                            {
                                fName = fieldnames[ii];
                            }
                            dt.Columns.Add(fName);
                        }
                        firstRow = false;
                    }

                    foreach (string field in fields)
                    {
                        dt.Rows.Add(field);
                    }
                }

                dt.WriteXml(outputFile);
                dt.Dispose();
            }
        }
開發者ID:Brett1981,項目名稱:ReuseableClasses,代碼行數:68,代碼來源:CsvToXml.cs


注:本文中的System.Data.DataTable.WriteXml方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。