我现在从文本文件中获得相关数据,并导入到一个DataTable中,那种方法
能比较好的把这些数据插入到一个SQL Server的表中呢。

解决方案 »

  1.   

    public static string ReadTxt()
    {
    StreamReader inStr = null;
    string str = string.Empty;
    FileInfo textFile = new FileInfo(@"C:\test.txt");
    inStr = textFile.OpenText();
    //Console.WriteLine("\n Reading from text file: \n");
    string textLine = inStr.ReadLine();
    while(textLine != null)
    {
    str = str + "\n\r" + textLine;
    textLine = inStr.ReadLine();
                               //在这里插入数据库
    }
    inStr.Close();

    return str;
    }
      

  2.   


       最好是手工用SQL SERVER的导入向导,效率比你用代码快10倍.   :)