如何让查询返回超过1条记录? [英] How to get the query to return more than 1 record?

查看:78
本文介绍了如何让查询返回超过1条记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的方法返回多个查询结果。当前方法,只输出1条记录。请指教 - 谢谢



我尝试过:



< pre lang =SQL> SqlDataReader reader = command.ExecuteReader();
while (reader。 Read ())
{
string title = reader.GetString( 0 );
string body = reader.GetString( 4 );

string pub = reader [ publication_id]。ToString();
string iss = reader [ issue_id]。ToString();
string sid = reader [ STORYID]。ToString();


string c = url(title,pub,iss,sid);

DateTime dt = DateTime 。今天;

XElement xeRoot = new XElement( article);

XElement xeStatus = new XElement( status 已批准);
xeRoot。添加(xeStatus);

XElement xeTitle = new XElement( title,title);
xeRoot。添加(xeTitle);

XElement xeSubTitle = new XElement( subtitle,title);
xeRoot。添加(xeSubTitle);

XElement xeSynopsis = new XElement( synopsis,body + ...);
xeRoot。添加(xeSynopsis);

XElement xeURL = new XElement( url,c);
xeRoot。添加(xeURL);

XElement xeDisplayDate = new XElement( display_date,dt);
xeRoot。添加(xeDisplayDate);

XDocument xDoc = new XDocument(xeRoot);
return xDoc.ToString();

}
}
}
返回 null < /跨度>;

}

解决方案

嗯......让我们从你的样本中删掉一些代码:

 SqlDataReader reader = command.ExecuteReader(); 
while (reader.Read())
{
string title = reader.GetString( 0 );
...
XDocument xDoc = new XDocument(xeRoot);
return xDoc.ToString();在$ $ $ $ $ $ $ $

I would like to get my method to return more than one query result. the current method, is only outputting 1 record. Please advise - Thank you

What I have tried:

SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        string title = reader.GetString(0);  
                        string body = reader.GetString(4);

                        string pub = reader["publication_id"].ToString();
                        string iss = reader["issue_id"].ToString();
                        string sid = reader["STORYID"].ToString(); 


                        string c = url(title, pub, iss, sid);

            DateTime dt = DateTime.Today;

            XElement xeRoot = new XElement("article");

            XElement xeStatus = new XElement("status", "Approved");
            xeRoot.Add(xeStatus);

            XElement xeTitle = new XElement("title", title);
            xeRoot.Add(xeTitle);

            XElement xeSubTitle = new XElement("subtitle", title);
            xeRoot.Add(xeSubTitle);

            XElement xeSynopsis = new XElement("synopsis", body + "...");
            xeRoot.Add(xeSynopsis);

            XElement xeURL = new XElement("url", c);
            xeRoot.Add(xeURL);

            XElement xeDisplayDate = new XElement("display_date", dt);
            xeRoot.Add(xeDisplayDate);

            XDocument xDoc = new XDocument(xeRoot);
            return xDoc.ToString();

                    }
                }
            }
            return null;
      
        }

解决方案

Well...let's rip some code out of your sample:

SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
    string title = reader.GetString(0);  
    ...
    XDocument xDoc = new XDocument(xeRoot);
    return xDoc.ToString();

}

You return from the method at the end of the first loop...


这篇关于如何让查询返回超过1条记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆