为什么我的while循环取出的值不是第一项就是最后一项重复出现啊???是不是跟没有跳出循环有关啊???但是我看不出来。请教!!!
SqlConnection conn1 = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
conn1.Open();
SqlCommand comm1 = new SqlCommand("select * from ExtendInfo where UserID='" + i + "' and ExtendInfoType = 0", conn1);
SqlDataReader read1 = comm1.ExecuteReader();
string faxlist = "";
while (read1.Read())
{
faxlist = "或"+read1["ExtendInfo"].ToString();
SqlConnection con1 = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
SqlCommand com1 = new SqlCommand("select * from ExtendInfo where UserID='" + i + "' and ExtendInfoType = 0", con1);
con1.Open();
SqlDataReader rd1 = com1.ExecuteReader();
while (rd1.Read())
{
faxlist =faxlist+"或" +rd1["ExtendInfo"].ToString();
}
rd1.Close();
con1.Close();
break;
}
lblFax.Text = faxlist;
read1.Close();
conn1.Close();
SqlConnection conn1 = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
conn1.Open();
SqlCommand comm1 = new SqlCommand("select * from ExtendInfo where UserID='" + i + "' and ExtendInfoType = 0", conn1);
SqlDataReader read1 = comm1.ExecuteReader();
string faxlist = "";
while (read1.Read())
{
faxlist = "或"+read1["ExtendInfo"].ToString();
SqlConnection con1 = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
SqlCommand com1 = new SqlCommand("select * from ExtendInfo where UserID='" + i + "' and ExtendInfoType = 0", con1);
con1.Open();
SqlDataReader rd1 = com1.ExecuteReader();
while (rd1.Read())
{
faxlist =faxlist+"或" +rd1["ExtendInfo"].ToString();
}
rd1.Close();
con1.Close();
break;
}
lblFax.Text = faxlist;
read1.Close();
conn1.Close();
conn1.Open();
SqlCommand comm1 = new SqlCommand("select * from ExtendInfo where UserID='" + i + "' and ExtendInfoType = 0", conn1);
SqlDataReader read1 = comm1.ExecuteReader();
string faxlist = "";
while (read1.Read())
{
faxlist =faxlist + "或"+read1["ExtendInfo"].ToString();
}
lblFax.Text = faxlist;
read1.Close();
conn1.Close();
SqlCommand com1 = new SqlCommand("select * from ExtendInfo where UserID='" + i + "' and ExtendInfoType = 0", con1);
还有那个i是怎么传的.
把问题描述清楚.还没明白LZ的意思.
SqlCommand com1 = new SqlCommand("select * from ExtendInfo where UserID='" + i + "' and ExtendInfoType = 0", con1);
这个语句呢?2,赋值语句是不是有问题
while (read1.Read())
{
faxlist = "或"+read1["ExtendInfo"].ToString();
//如果是想把全部数据显示出来,那应该是 faxlist += "或"+read1["ExtendInfo"].ToString();