This is a migrated thread and some comments may be shown as answers.

How to get query from sqldatasource by code

1 Answer 93 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
chava charoon
Top achievements
Rank 1
chava charoon asked on 27 Feb 2013, 01:27 AM
I looking for get query result from sqldatasource by C#  
because I want to custom something from query result and apply it to graph 

some thing like this

public class GraphItem
{
    public string name { get; set; }
    public double value { get; set; }
    public GraphItem(string name, double value)
    {
        this.name = name;
        this.value = value;
    }
}
 
private void chart1_NeedDataSource(object sender, EventArgs e)
{
    //Prepare graph value
    List<GraphItem> graphItemList = getQueryResult(sqlDataSource1);
     
    //Plot Graph
    Telerik.Reporting.Processing.Chart procChart = (Telerik.Reporting.Processing.Chart)sender;
    Telerik.Reporting.Chart defChart = (Telerik.Reporting.Chart)procChart.ItemDefinition;
    defChart.IntelligentLabelsEnabled = false;
    ChartSeries serie = new ChartSeries();
    serie.Type = ChartSeriesType.Pie;
    serie.Clear();
    serie.Appearance.LegendDisplayMode = Telerik.Reporting.Charting.ChartSeriesLegendDisplayMode.ItemLabels;
    foreach (GraphItem lst in graphItemList)
    {
        ChartSeriesItem item = new ChartSeriesItem();
        item.YValue = (double)lst.value;
        item.Name = (string)lst.name;
        item.Appearance.Exploded = true;
        item.Label.TextBlock.Text = (string)lst.name + " - #%";
        serie.Items.Add(item);
    }
    defChart.Series.Clear();
    defChart.Series.Add(serie);
}

How to built "getQueryResult(sqlDataSource1);" 
I don't know how to get query result from sqldatasoce

Thank for your response

1 Answer, 1 is accepted

Sort by
0
Hadib Ahmabi
Top achievements
Rank 1
answered on 28 Feb 2013, 12:09 PM
I don't believe you can. 
You can simply use SqlAdapter and SqlConnection to get the data directly from the database and feed it to a DataTable. 
Tags
General Discussions
Asked by
chava charoon
Top achievements
Rank 1
Answers by
Hadib Ahmabi
Top achievements
Rank 1
Share this question
or