如何将关键字搜索到多个XML字符串中并在gridview中显示所有搜索到的记录 [英] How to search a keyword into multiple XML string and display all searched records in gridview

查看:50
本文介绍了如何将关键字搜索到多个XML字符串中并在gridview中显示所有搜索到的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想搜索关键字(例如item_no),并且我在数据库中有多个表。在许多表中都可用.item_no。我必须在所有表格中搜索。只要它可用,它应该在gridview中显示。

我的问题是:会议记录与第一个表格中的gridview绑定,而不是从第二个表格绑定。而且当记录在第二张表中相遇时。然后数据集在gridview中显示为空白。

它将首先在part中搜索document等等...

我使用xml访问记录和表名。



请建议我。



谢谢



我尝试过:



i want to search a keyword(e.g item_no)and i have more than one table in a database.item_no available in many table. and i have to search in all table. wherever this is available it should be show in gridview.
My problem is: meeting records binds with gridview from 1st table only not from second table. moreover when records meet in 2nd table. then dataset came blank in gridview.
It will search in "part" first time then "document" and so on...
I am using xml for accessing the records and table name.

Please suggest me.

Thank you

What I have tried:

<itemtypes>
  <item type="part">
    <property1>id</property1>
    <property2>Name</property2>
    <property3>keyed_name</property3>
    <property4>item_number</property4>
    <property5>Revision</property5>
    <property6>type</property6>
  
  </item>
  <item type="document">
    <property1>id</property1>
    <property2>Name</property2>
    <property3>keyed_name</property3>
    <property4>item_number</property4>
    <property5>Revision</property5>
    <property6>type</property6>
 
  </item>
</itemtypes>




XmlNodeList elemList = xml.GetElementsByTagName("Item");

       for (int i = 0; i < elemList.Count; i++)
       {
           attrVal = elemList[i].Attributes["type"].Value;

           DataSet check = XmlBindInnovator();

           if (check.Tables.Count > 0)  //
           {
               continue;
           }
           else
               break;

       }



 private DataSet XmlBindInnovator()
   {
       StringBuilder sbAMLqry = new StringBuilder("");
       sbAMLqry.Append("<aml> <item type=""+ attrVal + "" action="get">");
       sbAMLqry.Append("<keyed_name>" + txtSearchBox.Text.Trim() + "</keyed_name>");
       sbAMLqry.Append("</item></aml>");

       Item result = ConnectionInnovator.inn.applyAML(sbAMLqry.ToString());
       string qryOutput = result.ToString();
       qryOutput = qryOutput.Replace("SOAP-ENV:Body", "RootResults");
       qryOutput = qryOutput.Replace(" id", " ids");



       XDocument xDocc = XDocument.Parse(qryOutput);
       string xmlResult = xDocc.Descendants("RootResults").DescendantNodes().First().ToString();

       StringReader srXML = new StringReader(xmlResult);
       ds.Reset();
       ds.ReadXml(srXML);
       GridView1.DataSource = ds;
       GridView1.DataBind();

       return ds;
   }

推荐答案

我得到了上述问题的解决方案。



I got the solution for above issue.

private void selectedColumn()
    {
      
        ds = null;
        GridView1.DataSource = ds;
        GridView1.DataBind();
        XmlDocument xml = new XmlDocument();
        // You'll need to put the correct path to your xml file here
        xml.Load(ConnectionInnovator.arasCol);

        elemList = xml.GetElementsByTagName("Item");
       
        for (i = 0; i < elemList.Count; i++)
        {
            attrVal = elemList[i].Attributes["type"].Value;
            XmlBindInnovator();
            
        }
    }


    private void XmlBindInnovator()
    {
        StringBuilder sbAMLqry = new StringBuilder("");                     
        sbAMLqry.Append("<AML> <Item type = '" + attrVal + "' action = 'get'>");
        sbAMLqry.Append("<keyed_name>" + txtSearchBox.Text.Trim() + "</keyed_name>");
        sbAMLqry.Append("</Item></AML>");

        Item result = ConnectionInnovator.inn.applyAML(sbAMLqry.ToString());
        string qryOutput = result.ToString();

        if (qryOutput.Contains("<faultcode>0</faultcode>"))
        {
         
        }
        else
        {
            qryOutput = qryOutput.Replace("SOAP-ENV:Body", "RootResults");
            qryOutput = qryOutput.Replace(" id", " ids");

            XDocument xDocc = XDocument.Parse(qryOutput);
            xmlResult = xDocc.Descendants("RootResults").DescendantNodes().First().ToString();
            
            StringReader srXML = new StringReader(xmlResult);
            ds.Reset();
            ds.ReadXml(srXML);           
            GridView1.DataSource = ds;
            GridView1.DataBind();
        } 
    }


我得到了上述问题的解决方案。



I got the solution for above issue.

private void selectedColumn()
    {      
        ds = null;
        GridView1.DataSource = ds;
        GridView1.DataBind();
        XmlDocument xml = new XmlDocument();
        // You'll need to put the correct path to your xml file here
        xml.Load(ConnectionInnovator.arasCol);

        elemList = xml.GetElementsByTagName("Item");
       
        for (i = 0; i < elemList.Count; i++)
        {
            attrVal = elemList[i].Attributes["type"].Value;
            XmlBindInnovator();
            
        }
    }


    private void XmlBindInnovator()
    {
        StringBuilder sbAMLqry = new StringBuilder("");                     
        sbAMLqry.Append("<AML> <Item type = '" + attrVal + "' action = 'get'>");
        sbAMLqry.Append("<keyed_name>" + txtSearchBox.Text.Trim() + "</keyed_name>");
        sbAMLqry.Append("</Item></AML>");

        Item result = ConnectionInnovator.inn.applyAML(sbAMLqry.ToString());
        string qryOutput = result.ToString();

        if (qryOutput.Contains("<faultcode>0</faultcode>"))
        {
         
        }
        else
        {
            qryOutput = qryOutput.Replace("SOAP-ENV:Body", "RootResults");
            qryOutput = qryOutput.Replace(" id", " ids");

            XDocument xDocc = XDocument.Parse(qryOutput);
            xmlResult = xDocc.Descendants("RootResults").DescendantNodes().First().ToString();
            
            StringReader srXML = new StringReader(xmlResult);
            ds.Reset();
            ds.ReadXml(srXML);           
            GridView1.DataSource = ds;
            GridView1.DataBind();
        } 
    }


这篇关于如何将关键字搜索到多个XML字符串中并在gridview中显示所有搜索到的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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