2012-08-16 80 views
0

我已经用ASP.Net以编程方式创建了图表,现在我只需要弄清楚如何连接到oracle sql开发人员数据库并检索数据以填充图表。以图形方式显示来自oracle sql表的数据

我会使用一个OleDb方法(见下文),以及其他一些逻辑?

 using System.Data.OleDb; 
     OleDbConnection myConnection = new OleDbConnection;(); 
     myConnection.ConnectionString = myConnectionString; 
     myConnection.Open(); 
     //execute queries, etc 
     myConnection.Close(); 

任何帮助将是伟大的。

+0

您是否正在填充数据集/表,并且您使用的是原始sql还是存储过程? – Justin 2012-08-16 18:48:26

回答

0

http://justins-fat-tire.blogspot.com/

我有一些代码示例,说明如何使用存储过程来填充数据集/表和获取的对象数据的泛型列表。如果你使用原始的sql,你将需要修改一下命令对象。

0

您将使用DataTable作为图表的数据源。为此,您首先需要填充表格。

public void Populate() 
{ 
    Datatable data = GetData(); 

    foreach(DataRow r in data.Rows) 
    { 
     /// Populate chart using data 
    } 
} 

public DataTable GetData() 
{ 
    try 
    { 
    OleDbConnection myConnection = new OleDbConnection;(); 
    myConnection.ConnectionString = myConnectionString; 
    myConnection.Open(); 

    OleDbCommand myCommand = myConnection.CreateCommand(); 

    //Set commandtype and text here. 
    myCommand.CommandType = SOMETYPE; 
    myCommand.CommandText = "SOMETEXT"; 

    OleDbDataReader reader = myCommand.ExecuteReader(); 

    DataTable t = new DataTable(); 
    t.Load(reader); 

    return t; 
    } 
    catch (Exception e) 
    { 
     throw e; 
    } 
    finally 
    { 
     myConnection.Close(); 
    } 
}