日期:2014-05-18 浏览次数:21207 次
int count=0;
try
  {
    
  for (int i = 0; i < dt.Rows.Count-1; i++)
  {
    
  fid =Convert.ToInt32(dt.Rows[i]["fid"].ToString());
  fname = dt.Rows[i]["fname"].ToString();
  fsellprice =Convert.ToDouble(dt.Rows[i]["fsellprice"].ToString());
  fnumber =Convert.ToInt32(dt.Rows[i]["fnumber"].ToString());
  funitprice =Convert.ToDouble(dt.Rows[i]["funitprice"].ToString());
  fbarcode =Convert.ToInt32(dt.Rows[i]["fbarcode"].ToString() );  
  sql = "insert into ftest(fid,fname,fsellprice,fnumber,funitprice,fbarcode) values(" + fid + ",'" + fname + "'," + fsellprice + "," + fnumber + "," + funitprice + "," + fbarcode + ")";
  MySqlCommand cmd = new MySqlCommand(sql, conn);
   count = Convert.ToInt32(cmd.ExecuteNonQuery());
  
  }
    
//if (count == 1)
  //{
  // MessageBox.Show("保存成功", "提示");
  //}
  //else
  //{
  // MessageBox.Show("保存失败", "提示");
  //}
    
  }
------解决方案--------------------
count 放到循环体外面定义,不就OK 了嘛