I have a stored procedure which, when executed, throws me a table dynamically. I would like that table to be stored in an array of Javascript, regardless of the number of fields or rows.
Is there any way to fill in from a SQL Server stored procedure?
Code C #:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
namespace Dash_Femsa
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
clsConexioncs conexion_server = new clsConexioncs();
conexion_server.Conexion = ConfigurationManager.ConnectionStrings["DefaultDW"].ToString();
//store
try
{
conexion_server.PreparaComandoSP("prm_spFEMSA_SemanasIndicadoresTelemetria");
conexion_server.LlenaComboConConsulta(lista_fechas, "Semana", "RangoFechas");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString().Trim());
}
}
}
}
It is important to mention that the procedure is executed from a C # method with web form, and it is sent to a page to generate graphs from the Google chart. I hope to have explained. Thanks.
This is my Javascript code:
<script type="text/javascript">
google.charts.load('current', { 'packages': ['bar'] });
google.charts.setOnLoadCallback(drawStuff);
function drawStuff() {
var data = new google.visualization.arrayToDataTable([
['Opening Move', 'Total'],
["Irapuato", 150],
["Celaya", 115],
["Coecillo", 94],
["Oriente León", 90],
['León Sur', 38]
]);
var options = {
title: 'Telemetría FEMSA',
width: 900,
legend: { position: 'none' },
chart: {
title: 'Telemetría FEMSA',
subtitle: 'Total por zona'
},
bars: 'horizontal', // Required for Material Bar Charts.
axes: {
x: {
0: { side: 'top', label: 'Totales' } // Top x-axis.
}
},
bar: { groupWidth: "90%" }
};
var chart = new google.charts.Bar(document.getElementById('grafica_semanal'));
chart.draw(data, options);
};
</script>