0

I am trying to read in sensor data which stored in a json file into a database every minute. But I have no idea how to read it in in visual basic or write it to the database.

Ive tried creating local sql databases but I as unable to access them through c# so I am attempting to use Access to store the data.

My json file
{
  "Chamber": {
    "Time": 8479,
    "Arduino": 0,
    "Chamber": 47,
    "Point": "Temperature",
    "Value": 22.81,
    "Unit": "c"
  }
}
Erik A
  • 31,639
  • 12
  • 42
  • 67
Incisor
  • 328
  • 1
  • 16
  • 2
    This is JSON, as you guessed it, so you just need to google: "excel vba json parse" and you'll find things like this: https://stackoverflow.com/questions/6627652/parsing-json-in-excel-vba – Fusseldieb Jul 02 '18 at 17:24
  • Welcome to stackoverflow NebulaNinja :) I suggest you to google "rest services" and read for a minute or two. You will have clear understanding how to solve this problem after that. :) – Ivan Kaloyanov Jul 03 '18 at 07:36
  • I mean not really because java script isn't what i am trying to do :/ – Incisor Jul 03 '18 at 21:42

1 Answers1

0

I used this code.

OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source= C:\Users\tlwhitten\Documents\Database2.accdb";

            int CO2 = 50;
            int Temperature = 50;

            OleDbCommand cmd = new OleDbCommand("INSERT into Data (CO2, Temperature) Values(@CO2, @Temperature)");
            cmd.Connection = conn;

            conn.Open();

            if (conn.State == ConnectionState.Open)
            {
                cmd.Parameters.Add("@CO2", OleDbType.VarChar).Value = CO2;
                cmd.Parameters.Add("@Temperature", OleDbType.VarChar).Value = Temperature;

                try
                {
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Data Added");
                    conn.Close();
                }
                catch (OleDbException ex)
                {
                    MessageBox.Show(ex.Source + " POOOOOPY");
                    conn.Close();
                }
            }
            else
            {
                MessageBox.Show("Connection Failed");
            }
In c#
Incisor
  • 328
  • 1
  • 16