日期:2014-05-17  浏览次数:20766 次

大神帮忙看看,老是报"IndexOutOfRangeException"
下面的插入数据库的操作已经屏蔽掉了,就单单读取近16000条数据就报错,使用文本分隔 还是一样报错!
int i = -1;
  using (StreamReader m_streamreader1 = new StreamReader(FilePath, Encoding.GetEncoding("GB2312")))
  {
  i = m_streamreader1.ReadToEnd().Split('\n').Length - 1;//获取行数
  }
  string l_path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
  int num = Convert.ToInt32(Math.Ceiling(i / 10000.00));//0x1869F0x82C_
  for (int ai = 1; ai <= num; ai++)
  {
  int flag = 0;
  string _path = l_path + "\\0x1869F0x82C_" + ai.ToString() + ".txt";
  File.Delete(_path);
  FileStream fs = new FileStream(_path, FileMode.CreateNew, FileAccess.ReadWrite);
  StreamWriter sw = new StreamWriter(fs, Encoding.GetEncoding("GB2312"));

  StreamReader m_streamreader1 = new StreamReader(FilePath, Encoding.GetEncoding("GB2312"));

  while (!m_streamreader1.EndOfStream)
  {
  if (flag == 0)
  {
  string str = m_streamreader1.ReadLine();
  sw.WriteLine(str);
  }
  else if (flag <= ai * 10000 && flag > (ai - 1) * 10000)
  {
  string str = m_streamreader1.ReadLine();
  sw.WriteLine(str);
  }
  else
  {
  if ((num - ai + 1) * 10000 < flag)
  {
  m_streamreader1.ReadToEnd();
  }
  else
  {
  m_streamreader1.ReadLine();
  }
  }
  flag++;
  }
  m_streamreader1.Close();
  sw.Close();
  fs.Close();
  }

  DBHelper dbhelper = new DBHelper();
  if (IsDel == 1)
  {
  dbhelper.IDM_Data("delete from GoodInfo");
  }

  progressBar1.Maximum = i;//设置最大长度值
  progressBar1.Value = 0;//设置当前值
  int fuck = 0;
  for (int bi = 1; bi <= num; bi++)
  {
  if (fuck == 12047)
  {
  string asdfasdf = "";
  }
  string _path = l_path + "\\0x1869F0x82C_" + bi.ToString() + ".txt";
  FileStream fs = new FileStream(_path, FileMode.Open, FileAccess.Read);
  StreamReader m_streamreader = new StreamReader(fs, Encoding.GetEncoding("GB2312"));
  m_streamreader.BaseStream.Seek(0, SeekOrigin.Begin);


  int k = 0;
  int columnCount = 0;


  SqlCeConnection con = new SqlCeConnection(dbhelper.CONN_STRING);
  try
  {
  while (!m_streamreader.EndOfStream)