java⼆维数组如何存⼊数据库
using System;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string m_strXML = "";
// 将⼆维数组序列化成XML
private void button1_Click(object sender, EventArgs e)
{
string[][] str = { new string[] { "1","2","3" }, new string[] { "A","B","C" } };
XmlSerializer xml = new XmlSerializer( str.GetType() );
System.IO.MemoryStream ms = new System.IO.MemoryStream();
XmlTextWriter writer = new XmlTextWriter(ms, Encoding.Default);
xml.Serialize(writer, str);
// 得到序列化后的XML字符串,可以直接保存到数据库
m_strXML = Encoding.Default.GetString(ms.ToArray());
MessageBox.Show(m_strXML);
}
// 把XML反序列化为⼆维数组
private void button2_Click(object sender, EventArgs e)
{
// 从数据库取出XML字符串,这⾥使⽤m_strXML变量
XmlSerializer xml = new XmlSerializer( typeof(string[][]) );
StreamReader sr = new StreamReader(new MemoryStream(System.Text.Encoding.Default.GetBytes(m_strXML)), System.Text.Encoding.Default);            string[][] str=(string[][])xml.Deserialize(sr);
foreach (string[] s1 in str)
typeof array{
foreach (string s2 in s1)
{
MessageBox.Show(s2);
}
}
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。