Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

XML
<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>

C#
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;
   }
Posted
Updated 17-May-16 2:14am
v2
Comments
Maciej Los 16-May-16 12:54pm    
Have you tried to use Linq? For example:
var result = xdoc.Descendants("item")
.SelectMany(x=>x.Descendants())
.Where(x=>x.Value == "item_number");

I got the solution for above issue.

C#
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();
        } 
    }
 
Share this answer
 
I got the solution for above issue.

C#
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();
        } 
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900