DataSet与XML导入导出方法

None.gif 忙活半天弄好了,又告诉我要以Excel形式导入导出。这点代码删了可惜,索性保存到这里。
None.gif
ExpandedBlockStart.gifContractedBlock.gif  
/**/ /// <summary>
InBlock.gif  
/// 导出考生信息到XML文件
InBlock.gif  
/// </summary>
ExpandedBlockEnd.gif  
/// <param name="toPath"></param>

None.gif    private   void  ExportToXml( string  toPath)
ExpandedBlockStart.gifContractedBlock.gif  
dot.gif {
InBlock.gif   
this.ds.WriteXml(toPath,XmlWriteMode.WriteSchema);
ExpandedBlockEnd.gif  }

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif  
/**/ /// <summary>
InBlock.gif  
/// 导入考生信息
InBlock.gif  
/// </summary>
ExpandedBlockEnd.gif  
/// <param name="fromPath">导入的XML文件</param>

None.gif    private   void  ImportFromXml( string  fromPath)
ExpandedBlockStart.gifContractedBlock.gif  
dot.gif {
InBlock.gif   
using(FileStream fsReadXml=new FileStream(fromPath,FileMode.Open))
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    XmlTextReader myXmlReader
=new XmlTextReader(fsReadXml);
InBlock.gif    ds_xml.ReadXml(myXmlReader);
InBlock.gif    myXmlReader.Close();
InBlock.gif    
int pbValue=1;
InBlock.gif    
int count=ds_xml.Tables[0].Rows.Count;
InBlock.gif    
//写入数据库
InBlock.gif
    foreach(DataRow dr in ds_xml.Tables[0].Rows)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     
try
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif      
this.pbProgress.Value=0;
InBlock.gif      
this.panProgress.Visible=true;
InBlock.gif      
this.lblMsg.Text="正在导入dot.gif"+dr["xjh"].ToString().Trim();
InBlock.gif      DB db
=new DB();
ExpandedSubBlockStart.gifContractedSubBlock.gif      SqlParameter[] paras
=dot.gif{
InBlock.gif              
new SqlParameter("@xjh",dr["xjh"].ToString().Trim()),
InBlock.gif              
new SqlParameter("@xxdm",dr["xxdm"].ToString().Trim()),
InBlock.gif              
new SqlParameter("@xm",dr["xm"].ToString().Trim()),
InBlock.gif              
new SqlParameter("@xb",dr["xb"].ToString().Trim()),
InBlock.gif              
new SqlParameter("@bh",dr["bh"].ToString().Trim()),
InBlock.gif              
new SqlParameter("@zp",dr["zp"]),
ExpandedSubBlockEnd.gif             }
;
InBlock.gif      
InBlock.gif      
if(ds.Tables["xs_ksxx"].Select("xjh='"+dr["xjh"]+"'").Length==0)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif       
string strInsertJBXX="insert into xs_jbxx(xjh,xxdm,xm,xb,bh,zp) values(@xjh,@xxdm,@xm,@xb,@bh,@zp)";
InBlock.gif          db.ExecCommand(strInsertJBXX,paras); 
ExpandedSubBlockEnd.gif      }

InBlock.gif      
else if(ds.Tables["xs_ksxx"].Select("xjh='"+dr["xjh"]+"'").Length==1)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif       
string strUpdateJBXX="update xs_jbxx set xxdm=@xxdm,xm=@xm,xb=@xb,bh=@bh,zp=@zp where xjh=@xjh";
InBlock.gif       db.ExecCommand(strUpdateJBXX,paras);
ExpandedSubBlockEnd.gif      }

InBlock.gif      System.Threading.Thread.Sleep(
10);
InBlock.gif      
this.pbProgress.Value=100;
InBlock.gif      
this.pbProgressAll.Value=(int)((pbValue/count)*100);
InBlock.gif      Application.DoEvents();
InBlock.gif      pbValue
++;
InBlock.gif      ds.Clear();
InBlock.gif      DataBind(rowfilter);
ExpandedSubBlockEnd.gif     }

InBlock.gif     
catch(Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif      
this.panProgress.Visible=false;
InBlock.gif      MessageBox.Show(ex.ToString());
ExpandedSubBlockEnd.gif     }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
this.panProgress.Visible=false;
ExpandedSubBlockEnd.gif   }

ExpandedBlockEnd.gif  }

None.gif
None.gif

转载于:https://www.cnblogs.com/syringa-flz/archive/2006/10/28/542565.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值