我想读取一个文件夹下所有文件(*.txt或*.excl 文件类型选其一)到数据库。数据库存入 用储存过程。
请大家帮忙一下尽量考虑一下效率

解决方案 »

  1.   

    string[] files=Directory.GetFiles("D:\");
    // files 为 字符串数组
      

  2.   

    数据库里面一条记录一个文件还是一条记录多个文件?取某种类型的文件可以这样
    string[] files = Directory.GetFiles(@"c:\xxx\", "*.txt");依次读取文件内容,写入数据库,至于怎么把二进制写入数据库,搜索一下,很多的
      

  3.   

    public void  Exsql(string sql,string tabel,string code , string name)
            {
                    open();
                    SqlCommand comm = new SqlCommand(sql, mydata.con);//sql为插入储存过程
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.Add(new SqlParameter("@tabel", SqlDbType.VarChar, 50)).Value = tabel;
                    comm.Parameters.Add(new SqlParameter("@a", SqlDbType.VarChar, 50)).Value = code;
                    comm.Parameters.Add(new SqlParameter("@b", SqlDbType.VarChar, 50)).Value = name;
                    mydata.ExecSql(comm);
                    close();
            }
       public void insetdata(string str)
            {
                string[][] tabel = rechar.tabel_Array(str, ' ', '^');//取得数据有100000条
                data _data = new data();
                
                for (int i = 0; i < tabel.Length; i++)
                    {
                      _data.Exsql("insert", "sz", tabel[i][0], tabel[i][1]);//调用上面的写入数据库。这样明显每次打开关闭数据库。肯定不行,请大家给我支支招
                    }
             }
      

  4.   

    实质上也就是把.csv文件导入到数据库(sql2005)
      

  5.   


     (输入路径后 会显示文件夹下的所有文件名称)using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;namespace ConsoleApplication2
    {
        class Program
        {
          
           static void Main(string[] args)
           {
               string pathnames = null;
               do
               {
                   Console.Write("\n请输入目录路径名(输入x退出程序):");
                   pathnames = Console.ReadLine();
                   if ((pathnames == "X") || (pathnames == "x"))
                       break;
                   DirectoryInfo di = new DirectoryInfo(pathnames);
                   if (di == null)
                   {
                       return;
                   }
                   FileSystemInfo[] fs = di.GetFileSystemInfos();
                   foreach (FileSystemInfo f2 in fs)
                   {
                       FileInfo file = f2 as FileInfo;
                       if (file != null)
                       {
                           Console.Write("\n"+file.Name);
                       }
                       else
                       {
                           CFileList FileListTest = new CFileList();
                           FileListTest.FileList(f2);
                       }
                   }
               } while (true);
               Console.Write("\n程序已终止,按任意键退出程序!");
               Console.ReadKey();  
      }
     }////
        class CFileList
        {
            public void FileList(FileSystemInfo f)//FileList为自己创建的方法
            {
                if (!f.Exists)//先判断f所指的文件或文件夹是否存在
                {
                    return;
                }
                DirectoryInfo di = f as DirectoryInfo;
                if (di == null)
                {
                    return;
                }
                FileSystemInfo[] fs = di.GetFileSystemInfos();//获取文件夹中所有文件和文件夹
                //下而对单个FileSystemInfo进行判断,如果是文件夹则进行递归操作
                foreach (FileSystemInfo f2 in fs)
                {
                    FileInfo file = f2 as FileInfo;
                    if (file != null)
                    {
                        Console.Write("\n"+file.Name);//如果是文件则将文件名加入到listBox1
                    }
                    else
                    {
                        FileList(f2);
                    }
                }        }    }
     ////
           
        }
      

  6.   

    string[] files = Directory.GetFiles(@"c:\xxx\", "*.txt");