private void comboBox9_SelectedIndexChanged(object sender, EventArgs e)
{
finish_day = Convert.ToInt32(comboBox9.Text);
}
private void comboBox10_SelectedIndexChanged(object sender, EventArgs e)
{
finish_month = Convert.ToInt32(comboBox10.Text);
}
private void comboBox11_SelectedIndexChanged(object sender, EventArgs e)
{
finfish_year = Convert.ToInt32(comboBox11.Text);
}
private void comboBox6_SelectedIndexChanged(object sender, EventArgs e)
{
begin_year = Convert.ToInt32(comboBox6.Text);
}
private void comboBox7_SelectedIndexChanged(object sender, EventArgs e)
{
begin_month = Convert.ToInt32(comboBox7.Text);
}
private void comboBox8_SelectedIndexChanged(object sender, EventArgs e)
{
begin_day = Convert.ToInt32(comboBox8.Text);
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Thread.Sleep(1000); // important
from_bs_2 += serialPort1.ReadExisting();
Thread.Sleep(1000);
this.Invoke(new EventHandler(showdata));
Thread.Sleep(1000);
}
private void showdata(object sender, EventArgs e)
{
int changdu = from_bs_2.Length;
if (changdu > 50)
{
chushihua++;
string fro;
string[] parm = new string[6];
textBox1.Text += from_bs_2;
fro = from_bs_2;
parm = fro.Split('\n');
string path = "C:\\Users\\COM\\Desktop\\data_logging.txt";
FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
for (int a = 0; a < 4; a++)
{
string[] zhongjian = new string[23];
zhongjian = parm[a].Split(';');
// textBox1.Text += zhongjian;
for (int keai = 0; keai < 23; keai++)
{
current[a, keai] = Convert.ToDouble(zhongjian[keai]);
sw.Write(current[a, keai]); sw.Write(';');
}
sw.WriteLine('/');
}
string[] zhongjian_2 = new string[23];
zhongjian_2 = parm[5].Split(';');
for (int m = 0; m < 23; m++) //
{
volatge[m] = Convert.ToDouble(zhongjian_2[m]);
sw.Write(volatge[m]); sw.Write(';');
}
sw.WriteLine('/');
DateTime dt = DateTime.Now; //strong text
int y = dt.Year; //
int yue = dt.Month; //
int d = dt.Day; //
int h = dt.Hour; //
int n = dt.Minute; //
textBox1.Text += y;
textBox1.Text += "-";
textBox1.Text += yue;
textBox1.Text += "-";
textBox1.Text += d;
textBox1.Text += "-";
textBox1.Text += h;
textBox1.Text += ":";
textBox1.Text += n;
textBox1.Text += "-";
textBox1.Text += "data logging times";
textBox1.Text += chushihua;
sw.Write(y); sw.Write("-"); sw.Write(yue); sw.Write("-"); sw.Write(d);
sw.Write("-"); sw.Write(h); sw.Write(":"); sw.Write(n); sw.WriteLine('/');
sw.Close();
fs.Close();
//////////////////time/////////////////////////////
string info = "INSERT INTO Logging_Data_2 (Time,Number,Power1,Power2,Power3,Power4,Power5,Power6,Power7,Power8,Power9,Power10,Power11,Power,Power12,Power13,Power14,Power15,Power16,Power17,Power18,Power19,Power20,Power21,Power22,Power23) values ('a',1,current[0, 0],current[0, 1],current[0, 2],current[0, 3],current[0, 4],current[0, 5],current[0, 6],current[0, 7],current[0, 8],current[0, 9],current[0, 10],current[0, 11],current[0, 12],current[0, 13],current[0, 14],current[0, 15],current[0, 16],current[0, 17],current[0, 18],current[0, 19],current[0, 20],current[0, 21],current[0, 22])";
using (System.Data.SQLite.SQLiteConnection connection = new System.Data.SQLite.SQLiteConnection("data source=logging_data.db"))
{
// connection.Open();
// using (DbTransaction transaction = connection.BeginTransaction())
// {
using (System.Data.SQLite.SQLiteCommand command = new System.Data.SQLite.SQLiteCommand(connection))
{
connection.Open();
command.CommandText = info;
//*emphasized text*command.ExecuteNonQuery();
}
// transaction.Commit();
// }
}
from_bs_2 = "";
if (textBox1.Text.Length > 1500)
{
textBox1.Text = "";
}
}
}
我要编写一个超级简单的文件,通过串行端口从arduino获取数据,如果我获取数据,则首先将它们记录在txt文件中,然后将它们发送到数据库中以备将来计算。因此,我安装了SQLite,并在其中编写了caode,但是当我对其进行测试时,我可以将数据记录到txt fime,但是数据库中什么也没有。
我建立了一个名为logging_data的数据库,该表为Logging_data_2,当我发现无法将任何数据记录到数据库中时,我只是将时间设置为'a',将数字设置为1,但仍然无法正常工作。寻求帮助,谢谢!