多条数据组合

deknight 2009-03-27 10:07:14
表A有字段id name
1 aa
2 bb
3 cc
... ...
... ...

表中数据可能是更多条
while循环后,希望得到
1,aa;2,bb;3,cc ...
该如何实现?多谢.
...全文
71 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hecong875 2009-03-27
  • 打赏
  • 举报
回复
表A有字段id name
1 aa
2 bb
3 cc
... ...
... ...

我连的MySQL,
MyCmd = new MySQLCommand("select * from A", MySQLConn);
MySQLDataReader MyRead = (MySQLDriverCS.MySQLDataReader)MyCmd.ExecuteReader();
string a ="";
while (MyRead.Read())
{
a +=MyRead["id"].tostring()+","MyRead["name"].tostring()+";"+;
}

试试!看成不!
我希望最后得到
1,aa;2,bb;3,cc ....
deknight 2009-03-27
  • 打赏
  • 举报
回复
................
deknight 2009-03-27
  • 打赏
  • 举报
回复
求助
deknight 2009-03-27
  • 打赏
  • 举报
回复
表A有字段id name
1 aa
2 bb
3 cc
... ...
... ...

我连的MySQL,
MyCmd = new MySQLCommand("select * from A", MySQLConn);
MySQLDataReader MyRead = (MySQLDriverCS.MySQLDataReader)MyCmd.ExecuteReader();
while (MyRead.Read())
{
string a=MyRead["id"].tostring();
string b=MyRead["name"].tostring();
}
我希望最后得到
1,aa;2,bb;3,cc ....
hecong875 2009-03-27
  • 打赏
  • 举报
回复
while循环?
你查询出来返回的是个什么数据集合?
while (rdr.Read())
{

co = this.SetReader(rdr);


}
private BrandInfo SetReader(SqlDataReader rdr)
{
BrandInfo co = null;


co = new BrandInfo();
co.Id = rdr.GetInt32(0);

if (!rdr.IsDBNull(1))
co.Name = rdr.GetString(1);
else
co.Name = "";

if (!rdr.IsDBNull(2))
co.Remark = rdr.GetString(2);
else
co.Remark = "";


return co;

}
是要这个??

deknight 2009-03-27
  • 打赏
  • 举报
回复
没人帮忙吗....
deknight 2009-03-27
  • 打赏
  • 举报
回复
求解
avengercf 2009-03-27
  • 打赏
  • 举报
回复
没玩过MYSQL 不过SQL语句应该是一样的吧
select id+','+name as idandname from a

循环里直接
a +=MyRead["idandname "].tostring()+";";

SQL中还可以用SQL函数直接返回你要的串

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧