【发布时间】:2011-04-30 22:51:12
【问题描述】:
我在 c# 的 Web 服务中有一个结构。当我使用“从 TABLE1 中选择 *”时;在 WebMethod 中,我得到了一个完全填充的结构。但是当我添加一个 WHERE 子句时,我得到 null 作为响应。为什么是这样?我到处寻找简单的解释,但没有找到。
如何使用SELECT * FROM TABLE1 WHERE _id=" + id "'"; 如果我只想从数据库中检索单个帖子,它可以正常工作,但当我收到多行响应时就不行了。
还有没有办法在 c# 中以任何方式对多行响应进行排序?
提前致谢!
编辑:
DataSet myDS = new DataSet();
try
{
myConnection.Open();
// Fill dataset with account data
//myCommand.Fill(myDS, "userdata");
myAdapter.Fill(myDS, "toplista");
myConnection.Close();
int i = myDS.Tables["toplista"].Rows.Count;
toplista[] mytoplista = new toplista[i];
i = 0;
foreach (DataRow row in myDS.Tables["toplista"].Rows)
{
mytoplista[i].name = row["_name"].ToString();
mytoplista[i].points = int.Parse(row["_points"].ToString());
mytoplista[i].level = row["_level"].ToString();
i++;
}
return mytoplista;
【问题讨论】:
-
是否需要遍历结果集并添加结构列表。
-
不看代码很难判断。顺便说一句,我建议您使用参数化查询而不是您当前获得 WHERE 子句的方式。