给你一个稍微复杂一点的查询,我设计的
看上图我把第一列标签后面的控件命名有规律,比如计划工厂后面文本框是"计划工厂t",Exapt命名为"计划工厂c",后面还隐藏一个listbox,命名为"计划工厂l"。
计划工厂 这个名称本身就是我要查询的表里面包含的字段。
利用这种界面,我要完成一些复杂点的查询:点文本框里的小图标按钮,d出工具,可以输入多条件,条件可以成立为模糊条件(用代替不认识部分),也可以成立为否决条件。
选中Exapt全部否定所成立条件;点击执行按钮,有条件的成立条件,无条件的不成立。
所以这种东西贯穿软件我就不能每个都去做,就只能写一个类文件:
public class conditionset{
public void load_condit(Panel p)
{
foreach (Control ctl in pControls)
{
if (ctl is SkinTextBox)
{
SkinTextBox sktxt = (SkinTextBox)pControls[ctlName];
ListBox list = (ListBox)pControls[sktxtNameSubstring(0, sktxtNameLength - 1) + "l"];
sktxtIconClick += (Object sen, EventArgs ed) =>
{
ctlcondition toolform = new ctlcondition();
if (listItemsCount > 0)
{
sktxtText = "┅";
sktxtReadOnly = true;
}
foreach (var sm in listItems)
{
toolformdvRowsAdd(smToString());
}
toolformShow();
toolformcleari += (Object send, EventArgs er) =>
{
sktxtText = "";
sktxtReadOnly = false;
};
toolformsubm += (Object send, EventArgs er) =>
{
listItemsClear();
foreach (DataGridViewRow dvr in toolformdvRows)
{
if (ConvertToString(dvrCells[0]Value) != "")
{
listItemsAdd(ConvertToString(dvrCells[0]Value));
}
}
sktxtText = "┅";
sktxtReadOnly = true;
};
};
}
}
}
public string condit(Panel p)
{
string master_condition = "";
foreach (Control ctl in pControls)
{
//遍历panel查找条件
#region
string condition = "";
if (ctl is SkinTextBox)
{
//文本框条件组合
#region
SkinTextBox sktxt = (SkinTextBox)pControls[ctlName];
string ziduan_name = sktxtNameSubstring(0, sktxtNameLength - 1);
SkinCheckBox skck = (SkinCheckBox)pControls[ctlNameSubstring(0, ctlNameLength - 1) + "c"];
ListBox list = (ListBox)pControls[ctlNameSubstring(0, ctlNameLength - 1) + "l"];
if (sktxtText != "")
{
if (sktxtText == "┅")
{
string blur_str = "", blur = "";
foreach (var itm in listItems)
{
if (itmToString()Contains(""))
{
if (skckChecked == true)
{
blur += " and " + ziduan_name + " not like '" + itmToString()Replace("", "%") + "'";
}
else
{
blur += " or " + ziduan_name + " like '" + itmToString()Replace("", "%") + "'";
}
}
else
{
blur_str += "'" + ConvertToString(itm) + "',";
}
}
string blur_sql = (blur == "") "" : blurSubstring(4, blurLength - 4)Trim();
string in_condition = "", like_condition = "";
if (skckChecked == true)
{
in_condition = ziduan_name + " not in ";
like_condition = " and ";
}
else
{
in_condition = ziduan_name + " in ";
like_condition = " or ";
}
string contains_sql = (blur_str == "") "" : in_condition + "(" + blur_strSubstring(0, blur_strLength - 1) + ")";
condition = contains_sql + blur_sql;
if (blur_sql != "" && contains_sql != "")
{
condition = contains_sql + like_condition + blur_sql;
}
else
{
condition = contains_sql + blur_sql;
}
}
else
{
if (!sktxtTextContains(""))
{
if (skckChecked == true)
{
condition = ziduan_name + "<>'" + sktxtText + "'";
}
else
{
condition = ziduan_name + "='" + sktxtText + "'";
}
}
else
{
if (skckChecked == true)
{
condition = ziduan_name + " not like '" + sktxtTextReplace("", "%") + "'";
}
else
{
condition = ziduan_name + " like '" + sktxtTextReplace("", "%") + "'";
}
}
}
}
#endregion
}
if (ctl is SkinDateTimePicker)
{
//日期条件组合
#region
if (ctlNameSubstring(ctlNameLength - 1, 1) != "t")
{
SkinDateTimePicker skdate_sta = (SkinDateTimePicker)pControls[ctlName];
SkinDateTimePicker skdate_end = (SkinDateTimePicker)pControls[ctlName + "t"];
if (skdate_statext != "")
{
if (skdate_endtext == "")
{
condition = skdate_staName + "='" + skdate_statext + "'";
}
else
{
condition = skdate_staName + ">='" + skdate_statext + "' and " + skdate_staName + "<='" + skdate_endtext + "'";
}
}
}
#endregion
}
master_condition += (condition == "") "" : "(" + condition + ") and ";
#endregion //遍历panel查找条件
}
string condition_sql = (master_condition == "") "" : master_conditionSubstring(0, master_conditionLength - 5);
return condition_sql;
}
}
工具用一个窗体代替:
public partial class condition : Form{
public condition()
{
InitializeComponent();
}
public event EventHandler subm;
public event EventHandler cleari;
private void submit_Click(object sender, EventArgs e)
{
subm(sender, e);
thisDispose();
}
private void clearit_Click(object sender, EventArgs e)
{
thisDispose();
dvRowsClear();
cleari(sender, e);
}
}
当我们执行多条件的时候就等于拼接条件
select from (select from xxx where xx)as T join (select from T where yyy ) as S on Tid=Sid
这样子是不对的,不知道mysql支持CTE的写法不,支持的话,可以写和你类似的语句
select
from xxx T
join(
select
from xxx T
where xxx
and yyy
) S on Sid=Tid
where xxx
public class testOra extends >
表中行的唯一性标识,可以由一个列或者多个列共同组成,但组成 主键约束 的所有列中元素不能为空。在同一表中,主键是唯一的。
(两个点,一个注意)
关键字: primary key
是为多个字段组合而成的主键,必须多条字段的值同时都不相同
如果为某两个或多个字段设置了组合字段主键约束的话,必须它们共同组合起来不能重复,但是单个字段重复的话是可以存在或通过的。
案例分析:
字段名 数据类型(长度) not null
书写格式:
案例分析:
increment:增加
auto:自动的
案例分析:
以上就是关于C#连接mysql数据库如何实现多条件查询全部的内容,包括:C#连接mysql数据库如何实现多条件查询、数据库 查询结果作为表和连接条件的表、java如何连接oracle数据库,并根据所输入的条件将数据库中的相关内容显示在jsp页面的table中等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)