OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter="文本文件|*.txt"; if(ofd.ShowDialog()==false) { return; } //IEnumerable<string> lines = // File.ReadLines(ofd.FileName,Encoding.Default); string[] lines = File.ReadLines(ofd.FileName, Encoding.Default).ToArray(); //foreach (string line in lines) //{ //} //跳过第一行表头 for (int i = 1; i < lines.Count(); i++) { //string line = lines.ElementAt(i); string line = lines[i]; //注意文件里是按照制表符分割的,不是字符串 string[] strs = line.Split(' ');//vs里 ' '为制表符 string startTelNum = strs[0]; string city = strs[1]; city = city.Trim('"');//去掉两边的双引号:"北京市" string telType = strs[2]; telType = telType.Trim('"'); SqlHelper.ExecuteNonQuery(@"Insert into T_TelNum(StartTelNum,TelType,TelArea) values(@StartTelNum,@TelType,@TelArea)", new SqlParameter("@StartTelNum",startTelNum), new SqlParameter("@TelType", telType), new SqlParameter("@TelArea", city)); }