2
I have a problem showing the data of a column on sqlserver, to insert as x and y in my Chart in Asp.net.
The problem is this, it seems the method (DataBindTable) is waiting for IEnumerable but my SqlDataReader does not implement IEnumerable.
If you could give me examples of how to overcome this difficulty I would appreciate.
Here follows the insertion code:
protected void Chart1_Load13(object sender, EventArgs e)
{
    string cs = ConfigurationManager.ConnectionStrings["CS"].ConnectionString;
    using (SqlConnection con = new SqlConnection(cs))
    {
        SqlCommand cmd = new SqlCommand("SELECT [Consumo_Medio_Real], [Tipo_de_Fatura]  FROM [dbo].[t_faturas]", con);
        con.Open();
        SqlDataReader rdr = cmd.ExecuteReader();
        Chart1.DataBindTable(rdr,"Consumo_Medio_Real");
    }
}
This is the connection code:
<connectionStrings>
    <add name="CS" connectionString="Data Source=ASUS;Initial Catalog=DB_SACC;Persist Security Info=True;User ID=sa;Password=1234" 
         providerName="System.Data.SqlClient" />
</connectionStrings>
Here are the usings:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Windows.Forms; 
using System.IO;
using Microsoft.Office.Interop.Excel;
using Excel = Microsoft.Office.Interop.Excel;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using System.Data;
using System.ComponentModel;
using System.Threading;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using System.Configuration;
using System.Web.UI.DataVisualization.Charting;
using System.Data.DataTable;
thanks this to give this error any idea how to fix ? Error 2 'Datatable' is an ambiguous Reference between 'Microsoft.Office.Interop.Excel.Datatable' and 'System.Data.Datatable"
– Diogo Gomes
@Diogogomes updated response. Caused ambiguity pq in their
usingis already using a reference that also implements a classDataTable.– Ismael
I just put the usings to take a look thanks has been relentless @Smael
– Diogo Gomes
What you yourself quoted:
using Microsoft.Office.Interop.Excel. Look at this question for other information.– Ismael
or remove Microsoft.Office.Interop.Excel? @Ismael
– Diogo Gomes
Run the procedures of the question I sent you and this will clean up all unused references. If you remove manually, unknowingly, you can cause errors in your code. You can use it the way I put it in the answer, no problem:
var dt = new System.Data.DataTable();– Ismael
I thank you for your cooperation
– Diogo Gomes
thanks for your help this solved, was me quite user@ismael
– Diogo Gomes
@Diogogomes Mark this answer as accepted if you really solved your problem. At tour this is well explained.
– Ismael