相关文章推荐
怕老婆的柠檬  ·  ListBox ItemTemplate ...·  5 月前    · 
爱玩的鸡蛋面  ·  ComboBox 类 ...·  6 月前    · 
酷酷的芹菜  ·  Beyond ...·  9 月前    · 
有胆有识的键盘  ·  Java ...·  1 年前    · 
有情有义的卤蛋  ·  .NET Core 3.0 ...·  1 年前    · 
从未表白的遥控器  ·  how to close a ...·  1 年前    · 

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"];
}

}
}
}

<Window x:Class="WPF_APP.TheBasics" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/20 vb.net 的 Label 控件 label(标签) 控件 用于显示文本,是设计应用程序界面时经常要用到的 控件 之一, 主要是用于显示其他 控件 名称,描述程序运行状态或标识程序运行的结果信息等 等,响应程序的事件或跟踪程序运行的结果。 使用 Label 控件 的情况很多,但用 Label 控件 显示的信息一般都不是描述 Label 控件 自身的特性,而是描述其他 控件 的属性或特征(如名称等)。例如,可用 Lab... 查询 加上 条件 即可。 SqlConnection cn = new SqlConnection(); cn.ConnectionString = "server=.;database=yourdb;uid=sa;pwd=pwd"; cn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cmd.CommandText = ... //标准库+类————文本 查询 程序 //程序目的:允许一个用户在一个给定的文件中 查询 单词, // 查询 结果是(1)单词在文件中出现的次数以及(2)其所在行的列表(行号+该行全部文本)、 开始一个程序设计,一种好方法就是从需求出手,列出程序的操作 在用下拉框勾选 查询 的时候,需要组合 条件 ,但是 c# 里面没有Java类似mybatis框架能直接在mapper.xml生成动态sql,因为这里我就用了sql拼接(跟字符串拼接一样)。 DataSource ds = new DataSource(); SqlConnection conn = ds.GetConn(); conn.Open(); C# 根据 textbox 文本框的内容从数据库查找到相应的数据填充到该窗体的其它 textbox 控件 里,只是 textbox 控件 ,没有下拉框什么的,前两行是连接数据库 private void btnSeaSpecific_Click(object sender, EventArgs e) SqlConnection sqlConnection... 一. option button 与checkbox 1.在同一个窗体内增添了多个单选框,系统默认每次只选中一个单选按钮,若是 选择 一个框架Frame,那么则是在这个框架之内,每次选中一个单选按钮。 2.判定 option 按钮是否被选中,需要判定 option (i).value的值,若为True,则选中,若为False,则未被选中,或者根据 option .item(i)所得出的结果,同理,为True选中,为Fa... public void demo( DataTable dtJson){ partList.Clear(); //清空列表中原有的数据,避免数据重复 partList.Add(""); //添加空白行 Winform、WPF根据 textbox 、label、 combobox 等对数据库 进行 查询 并赋值给DataGirdView 控件 private void SearchInvestInfo(string year, string printId, string investId, string department) using (SqlConnection con = new SqlConnection(conStr))