Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Scatter Graph data from a database?

Hi There,
 
Is it possible to let the scatter graph get it's data from a table in an access database - and if - then how?
 
Thanks,
orc
0 Kudos
Message 1 of 2
(3,334 Views)

The graph itself does not have built in support for grabbing data from an access db. But you can use several of the .NET data access classes to grab that data and plot it for you. This example just pulls a column of doubles from an access db using ODBC. This might be a more complex operation for you depending on how your db and data is organized.

[C#]
//create a connection to the access db using ODBC
using(OdbcConnection connection = new OdbcConnection(@"DSN=mysource;DriverId=25;DBQ=C:\db1.mdb;FIL=MS Access;UID=admin"))
            {
                using(OdbcCommand command = new OdbcCommand())
                {
                    //open a connection
                    connection.Open();
                    command.Connection = connection;
                    //do some query
                    command.CommandText = "SELECT Field1 FROM Table2";
                    using(OdbcDataReader reader = command.ExecuteReader())
                    {
                        // grab the data returned and populate a double array
                        ArrayList array= new ArrayList();
               
                        while(reader.Read())
                        {
                            array.Add(reader.GetDouble(0));
                        }
                        double[] data = (double[])array.ToArray(typeof(double));

                        //plot the double array
                        waveformGraph2.PlotY(data);                       
                    }
                }
            }



I hope this helps
Bilal Durrani
NI
0 Kudos
Message 2 of 2
(3,314 Views)