vs2015 c#通过ComboBox选择查询类别并在TextBox输入条件进行查询
来源:互联网 发布:淘宝没发货店铺没了 编辑:程序博客网 时间:2024/05/16 16:06
t
using Sytem;
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 通过ComboBox选择查询类别并在TextBox输入条件进行查询
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("server=WINDOWS-CBBU2E6;database=OrderManagementSystem;Uid = sa; Pwd = sa123"); //连接数据库
cn.Open(); //打开连接的数据库
SqlDataAdapter dap = new SqlDataAdapter("SELECT * FROM dbo.Table_2", cn); //建立SQL语句与数据库的连接
DataSet ds = new DataSet(); //实例化DataSet类
dap.Fill(ds, "Table"); //添加SQL语句并执行
string[] arylist = new string[ds.Tables[0].Columns.Count]; //按照列数定义字符串数组
for (int i = 0; i < ds.Tables[0].Columns.Count; i++) //遍历列
{
arylist[i] = ds.Tables[0].Columns[i].ColumnName; //获取数据表中的列名
}
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
comboBox2.Items.Add(arylist[j]); //将列名添加到comboBox1控件中
}
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
SqlConnection conn;
private void button8_Click(object sender, EventArgs e)
{
if (this.comboBox2.SelectedIndex == 0)//comboBox2下拉框选择笫一项
{
conn = new SqlConnection("server=WINDOWS-CBBU2E6;database=OrderManagementSystem;Uid = sa; Pwd = sa123");
SqlCommand cmd = new SqlCommand("select * from dbo.Table_2 where A like '%" + textBox1.Text + "%'", conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds, "dbo.Table_2");
dataGridView1.DataSource = ds.Tables["dbo.Table_2"];
}
if (this.comboBox2.SelectedIndex == 1)
{
conn = new SqlConnection("server=WINDOWS-CBBU2E6;database=OrderManagementSystem;Uid = sa; Pwd = sa123");
SqlCommand cmd = new SqlCommand("select * from dbo.Table_2 where B like '%" + textBox1.Text + "%'", conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds, "dbo.Table_2");
dataGridView1.DataSource = ds.Tables["dbo.Table_2"];
}
if (this.comboBox2.SelectedIndex == 2)
{
conn = new SqlConnection("server=WINDOWS-CBBU2E6;database=OrderManagementSystem;Uid = sa; Pwd =sa123");
SqlCommand cmd = new SqlCommand("select * from dbo.Table_2 where C like '%" + textBox1.Text + "%'", conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds, "dbo.Table_2");
dataGridView1.DataSource = ds.Tables["dbo.Table_2"];
}
if (this.comboBox2.SelectedIndex == 3)
{
conn = new SqlConnection("server=WINDOWS-CBBU2E6;database=OrderManagementSystem;Uid = sa; Pwd = sa123");
SqlCommand cmd = new SqlCommand("select * from dbo.Table_2 where D like '%" + textBox1.Text + "%'", conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds, "dbo.Table_2");
dataGridView1.DataSource = ds.Tables["dbo.Table_2"];
}
}
}
}
- vs2015 c#通过ComboBox选择查询类别并在TextBox输入条件进行查询
- asp中在一个页面输入查询条件,另一个页面的textbox中实现显示,修改和删除
- 按某个条件在Sqlite进行查询
- C# Winform ComboBox 在输入内容时 会在下拉菜单中显示 根据输入内容查询的结果
- 使用combobox进行模糊查询
- C#连接MYSQL数据库并进行查询
- C#连接MYSQL数据库并进行查询
- C#连接MYSQL数据库并进行查询
- 多条件组合查询,并根据指定类别找出所有最小子类别的SQL语句备忘
- 通过组合条件对DAO进行查询操作
- Questions:连接两个表进行查询:可以输入或不输入查询条件的sql 语句
- 分组并通过条件查询最值中的最小值
- Yii框架进行多条件查询,并分页
- 多条件查询数据列表并进行分页
- Combobox通过输入框所输入内容的改变实现模糊查询
- android SQLite查询并显示用户输入的选择信息
- Jquery实现边输入边查询,仿百度,并可以选择查询的值赋到输入框
- 实现textbox输入时模糊查询
- 你能否为心爱的主播守住阵地?详扒!直播App哪家强
- Windows 10 手机终于要升级到 64 位了,还有人喜大普奔吗?
- 邀请函 |“迈向数据法学”研讨会暨征文启事
- AndroidStudio 使用gradle依赖过程出现的问题
- 高并发量服务器性能解决方案
- vs2015 c#通过ComboBox选择查询类别并在TextBox输入条件进行查询
- linux win双系统时间差8小时解决方法。
- 一篇文章告诉你,小米如何玩转“人工智能” | CCF-GAIR
- 分享 :用五个趣味案例教你数据分析的基本思想
- 卸任蚂蚁金服 CEO 的彭蕾,这些年为阿里带来了哪些改变
- python应用系列教程——python使用smtp协议发送邮件:html文本邮件、图片邮件、文件附件邮件
- 锤子 T3 入网工信部,正面酷似 iPhone
- 面向程序员的数据挖掘指南(五)
- 【干货分享】深入浅出解析大数据平台架构