资源简介
C#空气质量监测管理系统.7z
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 空气质量监测管理系统
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
//获取地址
static string url = “Data Source=.;Initial Catalog=AirQualityDB;User ID=陈世洲;Password=123456“;
//创建SqlConnection对象
SqlConnection conn = new SqlConnection(url);
//创建DataSet对象
DataSet ds = new DataSet();
//窗体加载事件
private void Form2_Load(object sender EventArgs e)
{
//显示下拉框信息
ShowStatic();
}
//显示下拉框信息
public void ShowStatic() {
//定义sql语句
string sql = “select StationIDStationName from StationInfo“;
//创建SqlDataAdapter对象
SqlDataAdapter data = new SqlDataAdapter(sqlconn);
//填充数据
data.Fill(ds “StationInfo“);
//绑定数据
this.cb_typeName.DataSource = ds.Tables[“StationInfo“];
this.cb_typeName.ValueMember = “StationID“;
this.cb_typeName.DisplayMember = “StationName“;
}
//提交按钮
private void bt_insert_Click(object sender EventArgs e)
{
//异常处理
try
{
//非空检验
if (this.tb_Name.Text.Trim().Equals(““) || this.tb_StartTime.Text.Trim().Equals(““) || this.tb_StopTime.Text.Trim().Equals(““) || this.tb_Pm.Text.Trim().Equals(““) || this.tb_Level.Text.Trim().Equals(““) || this.tb_zy.Text.Trim().Equals(““))
{
MessageBox.Show(“所有信息都不能为空“ “操作提示!“ MessageBoxButtons.OK MessageBoxIcon.Information);
}
else
{
//打开连接
conn.Open();
//定义sql语句
string sql = “insert into AirQualityInfo values(“+this.cb_typeName.SelectedValue+“‘“+this.tb_Name.Text.Trim()+“‘‘“+this.tb_StartTime.Text.Trim()+“‘‘“+this.tb_StopTime.Text.Trim()+“‘“+this.tb_Pm.Text.Trim()+““+this.tb_Level.Text.Trim()+“‘“+this.tb_zy.Text.Trim()+“‘)“;
//创建sqlcommand对象
SqlCommand com = new SqlCommand(sql conn);
//执行sql语句
int i = com.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show(“添加成功!“ “操作提示!“ MessageBoxButtons.OK MessageBoxIcon.Information);
}
else
{
MessageBox.Show(“添加失败!“ “操作提示!“ MessageBoxButtons.OK MessageBoxIcon.Information);
}
}
}
- 上一篇:邮局选址问题
- 下一篇:c#飞机订票系统sql
评论
共有 条评论