点击进入远洋地带社区

字体:  

.net的效率问题。文本文件导入数据库

xuwu125 发表于: 2007-6-25 16:32 来源: 远洋门户

QUOTE:

用C#   做了一个windows应用程序,将一个文本文件导入数据库。   
  14M的文本文件,程序跑起来便没有响应了,看了下数据库,数据确实导入了   
  请问怎么才能提高程序的执行效率。   
  代码贴下面,请指出不足:   
  private   void   insertSql(string   str)   
  {   
  SqlConnection   conn   =new   SqlConnection("server=192.168.0.6;uid=sa;pwd=sa;database=databasename");   
  SqlCommand   cmd   =   new   SqlCommand("insert   into   test2005   values   ('"+   str+"')",conn);   
  conn.Open();   
  cmd.ExecuteNonQuery();   
  conn.Close();   
  cmd.Dispose();   
   
  }   
   
  private   void   button1_Click(object   sender,   System.EventArgs   e)   
  {   
   
  if   (openFileDialog1.ShowDialog()   ==   DialogResult.OK)   
  {   
  System.IO.StreamReader   sr   =   new   System.IO.StreamReader(openFileDialog1.FileName);   
  string   input;   
  while   (   (input=sr.ReadLine())   !=   null)   
  {   
  insertSql(input);   
  }   
  MessageBox.Show("导入成功!");   
  sr.Close();   
  }   
   
  }