日期:2014-05-18  浏览次数:20726 次

表里有数据呀,为什么就读不出来呢?
SqlCommand tm1 = new SqlCommand("select id,tid from tb_temp");
  tm1.Connection = conn1;
  //SqlDataReader dr3 = tm1.ExecuteReader();
  //if (dr3.Read())
  // {
  int i = 2;
  while (i < 12)
  {
  SqlDataReader dr3 = tm1.ExecuteReader();
  SqlCommand tm = new SqlCommand("update tb_shiti set dx1 = '" + dr3["tid"].ToString() + "' where id = '" + i + "'");
  tm.Connection = conn1;
  dr3.Dispose();
  tm.ExecuteNonQuery();
  i++;
  }

------解决方案--------------------
C# code

SqlCommand tm1 = new SqlCommand("select id,tid from tb_temp");
  tm1.Connection = conn1;
  SqlDataReader dr3 = tm1.ExecuteReader();
  while (dr3.Read())
   {
  int i = 2;
  while (i < 12)
  {
  SqlDataReader dr3 = tm1.ExecuteReader();
  SqlCommand tm = new SqlCommand("update tb_shiti set dx1 = '" + dr3["tid"].ToString() + "' where id = '" + i + "'");
  tm.Connection = conn1;
  dr3.Dispose();
  tm.ExecuteNonQuery();
  i++;
  }
}
dr3.Close();

------解决方案--------------------
C# code

SqlCommand tm1 = new SqlCommand("select id,tid from tb_temp");
  tm1.Connection = conn1;
  SqlDataReader dr3 = tm1.ExecuteReader();
  int i = 2;
  while (dr3.Read())
   {
  if (i < 12)//???
  {
  SqlCommand tm = new SqlCommand("update tb_shiti set dx1 = '" + dr3["tid"].ToString() + "' where id = '" + i + "'");
  tm.Connection = conn1;
  tm.ExecuteNonQuery();
  i++;
  }
}
dr3.Close();