(1)運行界面 (2)核心代碼 private void button9_Click(object sender, EventArgs e)//存厭氧數(shù)據(jù) { using (OleDbConnection connection = new OleDbConnection(connectionString)) { try { connection.Open(); MessageBox.Show("數(shù)據(jù)庫連接成功"); updatetimer2.Enabled = true; button9.BackColor = Color.Green; button9.Text = "數(shù)據(jù)庫已連接"; string dateString = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); if (this.textBox60.Text == "") { MessageBox.Show("插入數(shù)據(jù)不能為空"); } else { string reg = "insert into 厭氧系統(tǒng)(日期時間,沼氣流量,厭氧罐液位,厭氧罐溫度,沼液罐液位) values('" + dateString + "','" + this.textBox55.Text + "','" + this.textBox56.Text + "','" + this.textBox59.Text + "','" + this.textBox60.Text + "')"; OleDbCommand cmd = new OleDbCommand(reg, connection); cmd.CommandText = reg; cmd.ExecuteNonQuery(); MessageBox.Show("數(shù)據(jù)添加成功"); } } catch (Exception ex) { MessageBox.Show("數(shù)據(jù)庫連接失敗" + ex.Message); } } } private void updatetimer2_Tick(object sender, EventArgs e) { using (OleDbConnection connection = new OleDbConnection(connectionString)) { try { connection.Open(); string dateString = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); if (this.textBox60.Text == "") { MessageBox.Show("插入數(shù)據(jù)不能為空"); } else { string reg = "insert into 厭氧系統(tǒng)(日期時間,沼氣流量,厭氧罐液位,厭氧罐溫度,沼液罐液位) values('" + dateString + "','" + this.textBox55.Text + "','" + this.textBox56.Text + "','" + this.textBox59.Text + "','" + this.textBox60.Text + "')"; OleDbCommand cmd = new OleDbCommand(reg, connection); cmd.CommandText = reg; cmd.ExecuteNonQuery(); MessageBox.Show("數(shù)據(jù)添加成功"); } } catch (Exception ex) { MessageBox.Show("數(shù)據(jù)庫連接失敗" + ex.Message); } } } |
|