admin 发表于 2018-8-1 14:16:36

【Aras二次开发源码】使用ApplySQL进行快速查询




Technique
Use theInnovator.applySQL( … )method to submit SQL direct to the database.This
recipe returns the XML from theapplySQL()method and forms HTML for a table to
display the data.


C#
Innovator myInnovator = this.newInnovator();
Item results = myInnovator.applySQL(
"select login_name,first_name,last_name,email " +
"from " +
"order by last_name,first_name");

string content = "" +
"<style type='text/css'>" +
    "table {background:#000000;}" +
    "th {font:bold 10pt Verdana; background:#0000FF; color:#FFFFFF;}" +
    "td {font:normal 10pt Verdana; background:#FFFFFF;}" +
    "caption {font:bold 14pt Verdana; text-align:left;}" +
"</style>" +
    "<table id='tbl' border='0' cellspacing='1' cellpadding='2' datasrc='#itemData'>" +
    "<caption>User Directory</caption>" +
    "<thead>" +
      "<tr>" +
      "<th>Login Name</th>" +
      "<th>First Name</th>" +
      "<th>Last Name</th>" +
      "<th>EMail</th>" +
      "</tr>" +
    "</thead>" +
    "<tbody>";
   
XmlNodeList users = results.dom.SelectNodes("//recordset/row");
for (int i=0; i<users.Count; i++) {
content += "<tr><td>" + ((users.SelectSingleNode("login_name") != null) ?
                     users.SelectSingleNode("login_name").InnerText : "") + "</td>";   
   
content += "<td>" + ((users.SelectSingleNode("first_name") != null) ?
                     users.SelectSingleNode("first_name").InnerText : "") + "</td>";   
   
content += "<td>" + ((users.SelectSingleNode("last_name") != null) ?
                     users.SelectSingleNode("last_name").InnerText : "") + "</td>";   
         
content += "<td>" + ((users.SelectSingleNode("email") != null) ?
                     users.SelectSingleNode("email").InnerText : "") + "</td></tr>";   
   
}

content += "" +
    "</tbody>" +
"</table>";

return myInnovator.newResult(content);

页: [1]
查看完整版本: 【Aras二次开发源码】使用ApplySQL进行快速查询