0

I want to list sparql query result into textbox(multi line) or Grid view or list

But the code shown below returns only one result!

Please any help?

IGraph g = new Graph();
g.LoadFromFile("example.owl");

try
{
    SparqlQueryParser par = new SparqlQueryParser();
    SparqlQuery q = par.ParseFromString(@"PREFIX uni:<http://www.semanticweb.org/salim/ontologies/2018/10/university-ontology-2#>SELECT ?P_Name (COUNT(?P_Name) AS ?Material_Num)
        WHERE
        {
        ?P uni:Have ?Material;
           uni:P_Name ?P_Name.
        }
        GROUP BY ?P_Name");

    object results = g.ExecuteQuery(q);

    if (results is SparqlResultSet)
    {
        SparqlResultSet rset = (SparqlResultSet)results;

        foreach (SparqlResult r in rset)
        {
            TextBox1.Text = r.ToString();
            //or
            GridView1.DataSource = r.ToString();
            GridView1.DataBind();
        }
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    in your `foreach` loop you always overwrite datasource of the grid with `GridView1.DataSource = r.ToString();` - you have to put all results into a `List` and use this list as `DataSource` – UninformedUser Jun 06 '19 at 18:04
  • 1
    which code? Just convert the `SparqlResultSet` to a `List`, i.e. put everything into a list - this is basic .net ... and then do `GridView1.DataSource = YOUR_LIST` – UninformedUser Jun 08 '19 at 07:36
  • thank you... this what I want... and your reply solve my problem. – Salim Dada Jun 14 '19 at 17:37

0 Answers0