dynamic binding of chart from database in VS2010 in C#

▼魔方 西西 提交于 2020-01-04 04:08:29

问题


I have to create charts with dynamic datasource, I have a code. It does not show error but the graph is also not visible on runtime.

Here out_table is the name of my table and ADX is one of its column.

code:

OleDbConnection con1 = new OleDbConnection(@"PROVIDER=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=RS.accdb");
String sqlo = "Select ADX from " + out_table + "";
OleDbCommand myCommand = new OleDbCommand(sqlo, con1);
myCommand.Connection.Open();
OleDbDataReader myreader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
chart1.DataBindTable(myreader, "ADX"); 

回答1:


thanks for helping me. I have solved this problem, and for others, here is the solution. here, ds is dataset

       OleDbConnection con1 = new OleDbConnection(@"PROVIDER=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=RS.accdb");
         String sqlo = "Select * from " + out_table + "";
        OleDbDataAdapter da1 = new OleDbDataAdapter(sqlo, con);
        DataSet ds = new DataSet();
        da1.Fill(ds, in_table);
        DataView firstView = new DataView(ds.Tables[0]);
        chart1.Series[0].Points.DataBindXY(firstView, "ID", firstView, "ADX");


来源:https://stackoverflow.com/questions/9916659/dynamic-binding-of-chart-from-database-in-vs2010-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!