日期:2014-05-18 浏览次数:20714 次
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();
------解决方案--------------------
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();