{"id":8431,"date":"2023-02-07T16:51:31","date_gmt":"2023-02-07T07:51:31","guid":{"rendered":"https:\/\/www.auctionpro.co.kr\/?p=8431"},"modified":"2023-02-07T16:53:22","modified_gmt":"2023-02-07T07:53:22","slug":"datatable-serialize-%ec%98%a4%eb%a5%98","status":"publish","type":"post","link":"https:\/\/www.auctionpro.co.kr\/?p=8431","title":{"rendered":"DataTable Serialize \uc624\ub958"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Overview : DataTable\uc744 serialize\ud560 \uc218 \uc5c6\uc2b5\ub2c8\ub2e4. DataTable \uc774\ub984\uc774 \uc124\uc815\ub418\uc9c0 \uc54a\uc558\uc2b5\ub2c8\ub2e4 <br> DataSet \uacfc \ub2ec\ub9ac TableName \uc774\ub984\uc744 \ubc18\ub4dc\uc2dc \uc900\ub2e4.<\/h3>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:vim decode:true \">System.InvalidOperationException: XML \ubb38\uc11c\ub97c \uc0dd\uc131\ud558\ub294 \ub3d9\uc548 \uc624\ub958\uac00 \ubc1c\uc0dd\ud588\uc2b5\ub2c8\ub2e4. ---&gt; System.InvalidOperationException: DataTable\uc744 serialize\ud560 \uc218 \uc5c6\uc2b5\ub2c8\ub2e4. DataTable \uc774\ub984\uc774 \uc124\uc815\ub418\uc9c0 \uc54a\uc558\uc2b5\ub2c8\ub2e4.\n   \uc704\uce58: System.Data.DataTable.WriteXmlSchema(XmlWriter writer, Boolean writeHierarchy)\n   \uc704\uce58: System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.WriteXml(XmlWriter writer)\n   \uc704\uce58: System.Xml.Serialization.XmlSerializationWriter.WriteSerializable(IXmlSerializable serializable, String name, String ns, Boolean isNullable, Boolean wrapped)\n   \uc704\uce58: Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1_DataTable(Object o)\n   \uc704\uce58: Microsoft.Xml.Serialization.GeneratedAssembly.DataTableSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)\n   \uc704\uce58: System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)\n   --- \ub0b4\ubd80 \uc608\uc678 \uc2a4\ud0dd \ucd94\uc801\uc758 \ub05d ---\n   \uc704\uce58: System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)\n   \uc704\uce58: System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)\n   \uc704\uce58: System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)\n   \uc704\uce58: System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)\n   \uc704\uce58: System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)\n   \uc704\uce58: System.Web.Services.Protocols.WebServiceHandler.Invoke()<\/pre><\/div>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \" title=\"TableName \" >ds.TableName = _key;  \/\/* \ubc18\ub4dc\uc2dc \uba85\uc2dc \ud55c\ub2e4.<\/pre><\/div>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \">using System;\nusing System.Web;\nusing System.Data;\nusing System.Data.SqlClient;\n\nnamespace WebService1\n{\n    public class CacheClass\n    {\n        private static string _key = \"Customers\";\n\n        private static string connectionString = \"Data Source=localhost;\" + \"Initial Catalog=Northwind;user ID=sa\";\n\n        public static DataTable GetCustomerDataSet()\n        {\n            if (HttpContext.Current.Cache[_key] as DataTable == null)\n            {\n                \/\/ Recreate the item.             \n                string SQL = \"SELECT * FROM Customers\";\n                \/\/ Create ADO.NET objects.             \n                SqlConnection con = new SqlConnection(connectionString);\n                SqlCommand com = new SqlCommand(SQL, con);\n                SqlDataAdapter adapter = new SqlDataAdapter(com);\n\n                DataTable ds = new DataTable();\n                ds.TableName = _key;  \/\/* \ubc18\ub4dc\uc2dc \uba85\uc2dc \ud55c\ub2e4.\n\n                try\n                {\n                    con.Open();\n                    adapter.Fill(ds);\n                    HttpContext.Current.Cache.Insert(\"Customers\", ds, null, DateTime.Now.AddMinutes(60), TimeSpan.Zero);\n\n                }\n                catch (Exception err)\n                {\n                    System.Diagnostics.Debug.WriteLine(err.ToString());\n                }\n                finally\n                {\n                    con.Close();\n                }\n            }\n            return HttpContext.Current.Cache[_key] as DataTable;\n        }\n\n    }\n}<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Overview : DataTable\uc744 serialize\ud560 \uc218 \uc5c6\uc2b5\ub2c8\ub2e4. DataTable \uc774\ub984\uc774 \uc124\uc815\ub418\uc9c0 \uc54a\uc558\uc2b5\ub2c8\ub2e4 DataSet \uacfc \ub2ec\ub9ac TableName \uc774\ub984\uc744 \ubc18\ub4dc\uc2dc \uc900\ub2e4.<\/p>\n<\/div>","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[237],"tags":[],"class_list":["post-8431","post","type-post","status-publish","format-standard","hentry","category-memory-cache"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8431"}],"version-history":[{"count":0,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8431\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}