怎样将byte[]类型转换成Dataset类型的?各位大虾帮帮忙哈
14 个解决方案
Dataset的binary类型就是二进制,直接把byte[] 赋值给这个字段就可以
我是菜鸟呵呵,麻烦帮帮忙,有解决方案发哈我的油箱.huanghong@freesky.com.cn,谢谢了啊
如果是把dataset 变成 byte[] 然后经过数据传输后再转回dataset的话,那之前是怎么序列化的,现在就怎么反序列化
byte[]类型转换成Dataset类型
---------------------------
不同类型怎么转啊?
我反序列化要出错,二进制流不包含有效的二进制标头 就是这个错误,晕死了,感觉我好菜哦
1。DATASET 转化为 XML格式的STRING
private string DataSetToXml( DataSet xmlDS)
{
MemoryStream stream = null;
XmlTextWriter writer = null;
try
{
stream = new MemoryStream();
//从stream装载到XmlTextReader
writer = new XmlTextWriter(stream, Encoding.Unicode);
//用WriteXml方法写入文件.
xmlDS.WriteXml(writer);
int count = (int)stream.Length;
byte[] arr = new byte[count];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(arr, 0, count);
UnicodeEncoding utf = new UnicodeEncoding();
return utf.GetString(arr).Trim();
}
catch (System.Exception ex)
{
throw ex;
}
finally
{
if (writer != null) writer.Close();
}
}
2。STRING 转化为 byte[]
byte[] sendbyte = new byte[];
sendbyte = System.Text.Encoding.BigEndianUnicode.GetBytes(string.ToCharArray());
[网络传输]
3.byte[] 转化回STRING
string RecMessage = System.Text.Encoding.BigEndianUnicode.GetString(sendbyte);
4.XML格式的STRING 转化为 DATASET
public DataSet XmlToDataSet(string xmlData)
{
StringReader stream = null;
XmlTextReader reader = null;
try
{
DataSet xmlDS = new DataSet();
stream = new StringReader(xmlData);
//从stream装载到XmlTextReader
reader = new XmlTextReader(stream);
xmlDS.ReadXml(reader);
return xmlDS;
}
catch (System.Exception ex)
{
throw ex;
}
finally
{
if (reader != null) reader.Close();
}
}