读取txt文档

    string path = Server.MapPath("~\\BasicData\\"+name+".txt");
   StreamReader sr = new StreamReader(path, System.Text.Encoding.GetEncoding("gb2312"));

   String line;
   
   
if(name=="仓位" || name=="存储类型")

   {
    while ((line = sr.ReadLine()) != null) //取单行
    {
  
     string[] arrVal = line.Split('\t');
     string code, description,warehouse;

     code = arrVal[0].ToString();
     description = arrVal[1].ToString();
     warehouse=arrVal[2].ToString();

     strsql="insert into "+tablename+"(Code,Description,warehouse) values('"+code+"','"+description+"','"+warehouse+"')";
     cm.CommandText=strsql;
     cm.Connection=cn;
     cm.ExecuteNonQuery();

    }
   }

posted on 2008-03-05 17:30  heart-in-sky  阅读(202)  评论(0编辑  收藏  举报