可以动态增加、删除查询名和对应的条件(比如说查询条件在一个下拉菜单里、选择一个名,他对应得查询条件也可以跟着选择)如:请选择:(下拉菜单:名称、日期等等)(下拉菜单条件:包含、等于、先于、后于等等)(输入框:条件值)(增加条件按钮)(删除条件按钮)................这里往下增加或者删除以上的下拉菜单等控件
解决方案 »
- 定义“XAML”资源类
- 怎样编码使得DataGridView与数据库中的绑定数据同步?
- 求c#好书
- 在c1FlexGrid里,如何固定一列,而且,那列要可以编辑的
- 有关用VS2008对C#窗口应用程序进行打包并添加卸载的问题
- 鸟问题d
- winform 进度条 单线程还是多线程?
- 请教,弹出删除提示框后要再进行判断,再弹出提示框应怎么做?
- DataGridView dg = new DataGridView();请问dg若换成变量,应该怎么改写?
- 如何将数据库中的两个int字段在datagrid中的一列显示出来?
- 怪事,文本框的enter事件中 selectall()无效,加上一句 messagebox.show就起作用
- C#怎样获取文件相对路径
构建动态SQL语句查询数据
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
DataGridView DGV = new DataGridView(); public Form1()
{
InitializeComponent(); this.Size = new Size(500, 500); DGV.Parent = this;
DGV.Dock = DockStyle.Top;
DGV.AllowUserToAddRows = false;
DGV.EditMode = DataGridViewEditMode.EditOnEnter; DataTable DT = new DataTable(); DT.Columns.Add("Field");
DT.Columns.Add("Caption");
DT.Rows.Add(new Object[] { "A", "字段A" });
DT.Rows.Add(new Object[] { "B", "字段B" });
DT.Rows.Add(new Object[] { "C", "字段C" }); DataGridViewComboBoxColumn CC = new DataGridViewComboBoxColumn(); CC.HeaderText = "字段";
CC.DataSource = DT;
CC.ValueMember = "Field";
CC.DisplayMember = "Caption";
CC.DataPropertyName = "Field";
DGV.Columns.Add(CC); DT = new DataTable(); DT.Columns.Add("Operation");
DT.Rows.Add(new Object[] { ">" });
DT.Rows.Add(new Object[] { ">=" });
DT.Rows.Add(new Object[] { "=" });
DT.Rows.Add(new Object[] { "<" });
DT.Rows.Add(new Object[] { "<=" });
DT.Rows.Add(new Object[] { "like" }); CC = new DataGridViewComboBoxColumn();
CC.DataSource = DT;
CC.ValueMember = "Operation";
CC.DataPropertyName = "Operation";
DGV.Columns.Add(CC); DGV.Columns.Add("Value", "值"); DGV.Rows.Add(3); Button B = new Button();
B = new Button();
B.Parent = this;
B.Location = new Point(0, 200);
B.Click += new EventHandler(B_Click);
} void B_Click(object sender, EventArgs e)
{
String S = "SELECT * FROM TABLE WHERE (1==1) "; foreach (DataGridViewRow DR in DGV.Rows)
if (!String.IsNullOrEmpty((String)DR.Cells[0].Value))
S += " AND (" + DR.Cells[0].Value + DR.Cells[1].Value + DR.Cells[2].Value + ")"; MessageBox.Show(S);
}
}
}
Select * from Table Where (1==1) and (B) and (B) and (B)