Internal SQLite communication
Posted: Wed Feb 17, 2016 5:46 am
Hi,
I was wondering if anyone could give a few pointers as to how I can extract values from the interal SQLite database in a script module.
Which referenced assemblies do I need, and what is the connection string syntax for the interal db?
edit: Solved this while waiting ages for the post to be approved. If anyone else is interested, here's how I solved it:
Added the System.Data.SQLite dll in referenced assemblies. See code below for an example on how to read info from the DataLogger with SQL queries to the internal db.
I was wondering if anyone could give a few pointers as to how I can extract values from the interal SQLite database in a script module.
Which referenced assemblies do I need, and what is the connection string syntax for the interal db?
edit: Solved this while waiting ages for the post to be approved. If anyone else is interested, here's how I solved it:
Added the System.Data.SQLite dll in referenced assemblies. See code below for an example on how to read info from the DataLogger with SQL queries to the internal db.
Code: Select all
namespace Neo.ApplicationFramework.Generated
{
using System.Windows.Forms;
using System;
//import Data.SQLite, Reflection for interaction with DataLogger.
using System.Data.SQLite;
using System.IO;
using System.Drawing;
using System.Reflection;
using Neo.ApplicationFramework.Tools;
using Neo.ApplicationFramework.Common.Graphics.Logic;
using Neo.ApplicationFramework.Controls;
using Neo.ApplicationFramework.Interfaces;
public partial class SQLiteConnection
{
public void readSql(){
try {
bool UsbPresent = Directory.Exists("\\Hard Disk");
if(UsbPresent) {
//set up connection to internal SQLite database.
using (var myDb = new SQLiteConnection())
{
string executingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
myDb.ConnectionString = string.Format("data source={0}", Path.Combine(executingPath, "Database.db"));
//open connection to SQLite database.
myDb.Open();
//select entire database table (DataLogger1) for readout, sorted by time of entry.
string queryS = "select * from DataLogger1 order by Time asc";
using (var command = new SQLiteCommand(queryS, myDb))
using (SQLiteDataReader reader = command.ExecuteReader())
{
//loop through all rows in SQLite database.
while (reader.Read()) {
//do whatever you wish with the data here (using reader[x] for data posititions).
}
}
//close connection to SQLite database.
myDb.Close();
}
else {
//add actions to be run when USB is not found.
}
}
catch(Exception ex) {
//any error handling is to be placed here.
}
}
}
}