mysql如何存储传感器数据库_传感器采集来的数据怎么插入到数据库中?

展开全部

把传感器的采集的数据传入数据库,可62616964757a686964616fe59b9ee7ad9431333337393630以通过C#编程和ZIGBEE技术来实现啊,可以用visual stdio 2008或2010把串口程序写好,然后把用IAR 写好的软件下到目标板中就是ZigBee开发板,

程序中需要添加连接到数据库的函数,先建好数据库以及你要采集的信息数据的一个综合的表格,就是数据库中表格的各项列值,这个列的名称和串口程序里的值是一致的,附上代码表示using System.Data.SqlClient;

public partial class Form1 : Form

{

string ConStr;

SqlConnection conn;

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

ConStr = "server=.;database=Studend;Integrated Security=SSPI;";

conn = new SqlConnection(ConStr);

conn.Open();

string name = textBox1.Text;

name = "'" + name + "'";

string passwd = textBox2.Text;

try

{

SqlCommand sqlcom = new SqlCommand("insert into luo(name,password) values(" + name + " ," + passwd + ")", conn);

sqlcom.ExecuteNonQuery();

MessageBox.Show("连接成功!", "!");

} catch (Exception a)

{

MessageBox.Show("未添加!","!");

}

}

private void Form1_Load(object sender, EventArgs e)

{

ConStr = "server=.;database=Studend;Integrated Security=SSPI;";

conn = new SqlConnection(ConStr);

conn.Open();

if (conn.State == ConnectionState.Open)

{

label5.Text = "连接成功并打开数据库";

//conn.Close();

}

}

private void button3_Click(object sender, EventArgs e)

{

ConStr = "server=.;database=Studend;Integrated Security=SSPI;";

conn = new SqlConnection(ConStr);

conn.Open();

if (conn.State == ConnectionState.Open)

{

label5.Text = "连接成功并打开数据库";

//conn.Close();

}

}

private void button2_Click(object sender, EventArgs e)

{

ConStr = "server=.;database=Studend;Integrated Security=SSPI;";

conn = new SqlConnection(ConStr);

string name2 = textBox3.Text;

name2 = "'" + name2 + "'";

conn.Open();

try

{

SqlCommand sqlcom = new SqlCommand("delete from luo where name=" + name2, conn);

int a=sqlcom.ExecuteNonQuery();

if (a <=0)

{MessageBox.Show("删除失败!","!");

}

else MessageBox.Show("删除成功!", "!");

conn.Close();

}

catch (Exception a)

{

MessageBox.Show("未删除!","!");

}

}

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值