1
我在mysql数据库(在我的桌面)有一些照片(不大,只有8kb)。字段类型是blob。实际上我想将表格导出为xml文件,然后将其上传到我的数据库网站。但失败了。我尝试通过将表导出到xml文件然后将其导回到另一个表来模仿它(表的结构相同)。我可以做到,但我没有得到相同的照片(只有一些编码文本)。下面是一些代码片段:将mysql blob导出到xml,然后导入回不在d中得到相同的结果#
导出表为xml:
FileStream fs = new FileStream(filename,FileMode.Create,FileAccess.Write,FileShare.None);
StreamWriter sw = new StreamWriter(fs,Encoding.ASCII);
ds.WriteXml(sw); //write the xml from the dataset ds
导入XML到数据集:
FileStream fs = new FileStream(filename,FileMode.Open);
DataSet ds = new DataSet();
ds.ReadXml(fs);
写入数据集到另一个表:
...
int count = ds.Tables[0].Rows.Count;
for(int i=0;i<count;i++)
{
DataRow myDR = ds.Tables[0].Rows[i];
...
byte[] myphoto = null;
if(myDR["myphoto"].ToString().Length > 0)
{
myphoto = Encoding.ASCII.GetBytes(myDR["myphoto"].ToString().ToCharArray());
}
//insert the data to the mysql table
...
}
...
为什么我不能在这张另一张桌子上看到相同的照片?
对不起我的英文不好。
嗨马克,感谢您的回答。但我从数据集中直接写入xml。如何应用转换器? – satria 2011-02-07 06:59:49