首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

表里有数据呀,为什么就读不出来呢?该如何处理

2012-03-26 
表里有数据呀,为什么就读不出来呢?SqlCommand tm1 new SqlCommand(select id,tid from tb_temp)tm1.C

表里有数据呀,为什么就读不出来呢?
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(); 

热点排行