using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace zuoye2
{
public partial class frmCHA : Form
{
public frmCHA()
{
InitializeComponent();
}
//连接数据库据
string str = "Data Source=074B8J5ZEZU39W3\\SQLEXPRES;Initial Catalog=AirQualityDB;Integrated Security=True";
SqlConnection conn = new SqlConnection();//申明数据库连接
//主窗体
private void frmCHA_Load(object sender, EventArgs e)
{
BindAirQualityInfo();
}
//查询
private void BTNCHA_Click(object sender, EventArgs e)
{
}
public void BindAirQualityInfo()
{
SqlConnection conn = new SqlConnection(str);//连接
string cha = txtBoxCHA01.Text.Trim();//sql语句
string sql = string.Format("select * from AirQualityInfo,StationInfo where like '%{0}%'", cha);
SqlDataAdapter adapter = new SqlDataAdapter(sql,conn);//数据适配器
DataSet ds = new DataSet();//数据集
try
{
adapter.Fill(ds,"stu");//填充数据
dataGridView1.DataSource = ds;//绑定数据源
dataGridView1.Bind();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
BindAirQualityInfo();
}
private void txtBoxCHA01_TextChanged(object sender, EventArgs e)
{
}
}
}