求觖...读取符合条件的某一字段的所有值,以空格分开赋值给TextBox!
SqlStr = "SELECT count(*) as coc FROM quan_tags where bttype= ' " + Request[ "id "] + " ' ";
Cmd = new SqlCommand(SqlStr, conn);
SqlDataReader objreader8 = Cmd.ExecuteReader();
objreader8.Read();
int cc = (int)objreader8[ "coc "];
objreader8.Close();
int ccc=0;
for (int i = 1; i <= cc; i++)
{
SqlStr = "SELECT top 1 bid,bname FROM quan_tags where bttype= ' " + Request[ "id "] + " ' and bid> ' "+ccc+ " ' ";
Cmd = new SqlCommand(SqlStr, conn);
SqlDataReader objreader7 = Cmd.ExecuteReader();
objreader7.Read();
ccc = (int)objreader7[ "bid "];
tag_tb.Text=tag_tb.Text+(string)objreader7[ "bname "]+ " ";
objreader7.Close();
}
读取符合条件的某一字段的所有值,以空格分开赋值给TextBox!
请问以上代码正确吗???
还有就是看起来代码太多了,有没有简单一点的啊???
------解决方案--------------------SqlStr = "SELECT bid,bname FROM quan_tags where bttype= ' " + Request[ "id "] + " ' and bid> ' "+ccc+ " ' ";
Cmd = new SqlCommand(SqlStr, conn);
SqlDataReader objreader7 = Cmd.ExecuteReader();
using (objreader7)
{
while(objreader7.Read()
{
tag_tb.Text=tag_tb.Text+(string)objreader7[ "bname "]+ " ";
}
objreader7.Close();
}