首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

datagriedview依照其中某列值不同数据导出xml文件

2014-05-24 
datagriedview按照其中某列值不同数据导出xml文件问题一:如上图,根据运单号不同把DataGridView中的数据导

datagriedview按照其中某列值不同数据导出xml文件
datagriedview依照其中某列值不同数据导出xml文件
问题一:如上图,根据运单号不同把DataGridView中的数据导出不同的xml文件中,文件名以该运单来命名,请问怎么实现?


问题二:通过数据库查询可实现对不同运单作分类后的运单号+xml,请问怎么将数据库中的xml格式的数据列用C#编程导出到xml文件中。查询结果如下图
datagriedview依照其中某列值不同数据导出xml文件


说明,至于测试数据,大家可以随便写。

[解决办法]


   //按id不同形成不同的文件,文件内容是XML
   public void writexml(string id,string xml)
     {
            
         StreamWriter sw =new StreamWriter(Application.StartupPath + @"" + id + ".xml");
         try 
         {
            sw.WriteLine(xml);
            sw.Close();
         }
         catch (Exception ex )
         {
            MessageBox.Show(ex.Message);
         }   
     }
    private void button18_Click(object sender, EventArgs e)
    { 
        SqlConnection cnn=new SqlConnection();               
        cnn.ConnectionString = @"server=192.168.1.2;database=data;user id=sa;password=sa";
        cnn.Open();
        DataSet ds =new DataSet();        
        SqlDataAdapter da=new SqlDataAdapter("select * from table", cnn);        
        cnn.Close();
        da.Fill(ds, "table");        
        if(ds.Tables[0].Rows.Count==0)
        {            
            for(int i=0;i<ds.Tables[0].Rows.Count - 1;i++)
            {
                string id = ds.Tables[0].Rows[i]["CorpOrderID"].ToString();
                string xml = ds.Tables[0].Rows[i]["xmlCol"].ToString();
                writexml(id, xml);
            }
        
        }

    }





热点排行