现在已经通过调用sdk接口,获得温湿度信息,点击启动按钮后,每三秒钟可以接收数据,现在需要将数据存入数据库(暂时的思路是设计一个保存按钮 ,点击按钮后存入数据,但一直保存不了),请指导,提出更好的思路可以实时添加到数据库。(这是保存按钮的点击事件,请指导)
private void btnsave_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=TH;Integrated Security=True");
string wsdxx = rhtResult.Text;
string time = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
bool IsNoRight = false;
string sql = String.Format("SELECT * FROM wsd");
IsNoRight = TemHum.DataBaseHelper.GetDataSet(sql).Tables[0].Rows.Count > 0;
if (!IsNoRight)
{
sql = String.Format("INSERT INTO wsd(time,wsdxx) VALUES('{0}','{1}')",time,wsdxx);
TemHum.DataBaseHelper.GetNonQueryEffectedRow(sql);
MessageBox.Show(wsdxx + "添加成功!", "提示");
}
else
{
MessageBox.Show("添加失败!", "提示");
}
}