各位大哥:小弟有个非常难办的事情,就是怎么样把一个数据集datatable转换为字节数组,再将字节数组转换为数据集datatable,万分感谢!

解决方案 »

  1.   

    序列化
    请参见:
    BinaryFormatter 类
      

  2.   

    客户的机器不准装oracle客户端,必须经过socket传数据过来,然后转换为数据集,再进行其它操作。
      

  3.   

    那还要生成xml文件,并且要发送,这样进行io操作,性能问题会不会太大
      

  4.   

    XML的主要作用就是这个!
      

  5.   

    .NET 中的对象序列化
    http://www.microsoft.com/china/MSDN/library/archives/library/dndotnet/html/objserializ.asp
      

  6.   

    与我的一个datatable---string---datatable类似
    我的做法:
      DataTable dt = (DataTable)dataGrid1.DataSource;
                string str = null;
                int rowCount = dt.Rows.Count;
                int columnCount = dt.Columns.Count;
                for (int i = 0; i < rowCount; i++)
                {
                    for (int j = 0; j < columnCount; j++)
                    {
                        str += (dt.Rows[i][j].ToString() + "-");
                    }
                }
    string[] str = Encoding.Default.GetString(buffer, 0, read).Split(new char[] { '-', '|' });
                string[,] strb = new string[str.Length / 5 + 1, 5];
                int r = 0, c = 0;
                for (int i = 0; i < str.Length; i++)
                {
                    strb[r, c] = str[i];
                    c++;
                    if ((i + 1) % 5 == 0)
                    {
                        c = 0;
                        ++r;
                    }
                }  我的笨方法,还没找到更好的方法.寻求
      

  7.   

    序列化:
            Dim msgByte() As Byte
            Dim tb As New DataTable
            Dim bf As New BinaryFormatter
            Dim stream As New MemoryStream
            bf.Serialize(stream, tb)
            msgByte = stream.ToArray()
    反序列化:
            Dim msg() As Byte = receivingUdpClient.Receive(RemoteIpEndPoint)
            Dim dt as new DataTable
            Dim stream As MemoryStream = New MemoryStream(msg)
            Dim bf As New BinaryFormatter
            dt = bf.Deserialize(stream)  '收到消息