我正在尝试每分钟将存储在json文件中的传感器数据读入数据库。但是我不知道如何在Visual Basic中读取它或将其写入数据库。
我曾尝试创建本地sql数据库,但由于无法通过c#访问它们,因此我试图使用Access来存储数据。
My json file
{
"Chamber": {
"Time": 8479,
"Arduino": 0,
"Chamber": 47,
"Point": "Temperature",
"Value": 22.81,
"Unit": "c"
}
}
答案 0 :(得分:0)
我使用了这段代码。
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#