例1
userquery()
|
//没有查询条件;
|
userquery(dtbegin,-)
|
//只有开始时间;
|
userquery(-,dtend)
|
//只有结束时间;
|
userquery(dtbegin,dtend)
|
//指定每一时间;
|
userquery()
|
//没有查询条件;
|
userquery(datetime dtinput,bool bisbegin)
|
//bisbegin表示是否是开始时间,否则代表结束时间; |
userquery(datetime dtbegin,datetime dtend)
|
//具体指定了每个查询条件; |
public dataset userquery()
{
datetime dtbegin = new datetime(1900,1,1,0,0,0);
datetime dtend = new datetime(9999,12,31,23,59,59);
return userquery(dtbegin,dtend);
}
public dataset userquery(datetime dtinput, bool bisbegin)
{
datetime dtbegin;
datetime dtend;
if(bisbegin)
{
dtbegin = dtinput;
dtend = new datetime(9999,12,31,23,59,59);
}
else
{
dtbegin = new datetime(1900,1,1,0,0,0);
dtend = dtinput;
}
return userquery(dtbegin,dtend);
}
public dataset userquery()
{
datetime dttemp = new datetime(1900,1,1,0,0,0);
return userquery(dttemp,dttemp,false,false);
}
public dataset userquery(datetime dtinput, bool bisbegin)
{
if(bisbegin)
{
return userquery(dtinput,dtinput,true,false);
}
else
{
return userquery(dtinput,dtinput,false,true);
}
}
public dataset userquery(datetime dtbegin,datetime dtend)
{
return userquery(dtbegin,dtend,true,true);
}
private dataset userquery(datetime dtbegin,datetime dtend, bool bneedbegin,bool bneedend)
{
string strsql = “select a.somefields from a where 1=1”;
if(bneedbegin)
{
strsql += ” and a.fdbegindate>=@dtbegin”;
}
if(bneedend)
{
strsql += ” and a.fdenddate<=@dtend”;
}
//do some query
….
return a dataset;
}
例2
querycaption(string strid)
|
//单参数;
|
querycaption(string[] stridarr)
|
//数组参数;
|
select tb_namelib_3.name obj3_name from tb_namelib_3 where tb_namelib_3.name_id= obj1_id;
select tb_namelib_4.name obj4_name from tb_namelib_4 where tb_namelib_4.name_id= obj2_id;
下面用union合成取数据过程
datarowcollection objrows = dataset1.tables[0].rows;
int icount = objrows.count;
string[] strsqlarr = new string[icount];
string strsql;
string strfields;
string strobjid1;
string strobjid2;
dataset objdataset;
for(int i=0;i<icount;i++)
{
strobjid1 = objrows[i][“obj1_id”].tostring();
strobjid2 = objrows[i][“obj2_id”].tostring();
strfields = “’”+strobjid1 +”’ obj1_id, “;
strfields+= “’”+objrows[i][“obj1_name”].tostring()+”’ obj1_name, “;
strfields+= “’”+strobjid2 +”’ obj2_id, “;
strfields+= “’”+objrows[i][“obj2_name”].tostring()+”’ obj2_name, “;
strsqlarr[i] = ” union select “+ strfields +” tempu. obj3_name,tempj.obj4_name, from (select 1 pid, tb_namelib_3.name obj3_name from tb_namelib_3 where tb_namelib_3.name_id=””+ strobjid1 +”””) tempu left join (select 1 pid, tb_namelib_4.name obj4_name from tb_namelib_4 where tb_namelib_4.name_id= “”+ strobjid2 +””) tempj on tempu.pid = tempj.pid union select “+ strfields +” tempu.obj3_name,tempj.obj4_name, from (select 1 pid, tb_namelib_3.name obj3_name from tb_namelib_3 where tb_namelib_3.name_id= “”+ strobjid1 +””) tempu righter join (select 1 pid, tb_namelib_4.name obj4_name from tb_namelib_4 where tb_namelib_4.name_id= “”+ strobjid2 +””) tempj on tempu.pid = tempj.pid “;
}
if(icount>0)
{
if(null==strsqlarr[0])
{
return null;
}
strsqlarr[0] = strsqlarr[0].substring(6);
strsql = string.concat(strsqlarr);
//创建连接 persistconn m_objpersistconn = new persistconn();
//执行查询 objdataset = m_objpersistconn.executedataset(strsql);
//释放连接 m_objpersistconn.dispose();
return objdataset;
}
另外一个比较重要的问题是:如何在“有限”的情况下检验程序的性能。这里的“有限”是指不能够快速地使系统具有超大数据量或者复杂度。这时,我们可以考虑进行“逆境测试”,即通过降低server的配置或程序的简单修改从而能够在某种程度上模拟出一些性能问题。