⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 这是关于数据库中绑定到datagridwiew中的数据库技术
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 传感器数据库部分
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“传感器数据库DataSet.传感器数据总表”中。您可以根据需要移动或移除它。
            this.传感器数据总表TableAdapter.Fill(this.传感器数据库DataSet.传感器数据总表);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 myf = new Form2();
            myf.Show();
            //myf.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
           //查询记录
            try
            {
                this.dataSet1.Clear();
                string StrSQL = "SELECT * FROM 数据总表 WHERE ";  
                StrSQL += this.comboBox1.Text + " LIKE  '";
                StrSQL += this.textBox1.Text + "'";
                if (this.comboBox1.Text == "所有记录")
                    StrSQL = "SELECT * FROM 数据总表";
                this.oleDbDataAdapter1.SelectCommand.CommandText = StrSQL;
                this.oleDbDataAdapter1.SelectCommand.Connection = this.oleDbConnection1;
                //打开数据库连接
                this.oleDbConnection1.Open();
                //执行SQL命令
                this.oleDbDataAdapter1.SelectCommand.ExecuteNonQuery();
                //关闭连接
                this.oleDbConnection1.Close();
                //更新数据集
                this.oleDbDataAdapter1.Fill(this.dataSet1, "数据总表");
                dataGridView1.DataSource = dataSet1.Tables["数据总表"];
            }
            catch (Exception Err)
            {
                MessageBox.Show("查询数据集记录操作失败:" + Err.Message, "信息提示",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                //如果打开了连接,则关闭它
                if (this.oleDbConnection1.State == ConnectionState.Open)
                {
                    this.oleDbConnection1.Close();
                }
            }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -