求解析、在线等。
1. [WebMethod]
public DataTable QueryDatas1(string param1, string param2)
{
SqlConnection conn = new SqlConnection("server=.;database=ljptest;uid=sa;pwd=sa");
string sql1 = "select B.stano,A.deptname from dept A inner join stainfo B on A.stano=B.stano ";
if (param1 == "0")
{
sql1+=" where 1=1";
}
SqlCommand cmd = new SqlCommand(sql1, conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
return ds.Tables[0];
}
2.[WebMethod]
public DataTable QueryDatas2(string param1, string param2)
{
SqlConnection conn = new SqlConnection("server=.;database=ljptest;uid=sa;pwd=sa");
string sql2 = "select B.deptcode,C.names from consumes C inner join dept B on C.deptcode=B.deptcode";
if (param1 == "0")
{
sql2+=" where 1=1";
}
SqlCommand cmd = new SqlCommand(sql2, conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
return ds.Tables[0];
}
3.[WebMethod]
public DataTable QueryDatas3(string param1, string param2)
{
SqlConnection conn = new SqlConnection("server=.;database=ljptest;uid=sa;pwd=sa");
string sql3 = "select B.stano,D.doorname from y_mj_doors D inner join stainfo B on D.stano=B.stano ";
if (param1 == "0")
{
sql3+=" where 1=1";
}
SqlCommand cmd = new SqlCommand(sql3, conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
return ds.Tables[0];
}
4.[WebMethod]
public DataTable QueryDatas4(string param1, string param2)
{
SqlConnection conn = new SqlConnection("server=.;database=ljptest;uid=sa;pwd=sa");
string sql4 = "select B.stano,B.staname from stainfo B";
if (param1 == "0")
{
sql4+=" where 1=1";
}
SqlCommand cmd = new SqlCommand(sql4, conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
return ds.Tables[0];
}
怎么样才能把这个四个方法融合成一个方法呢。求解啊。各路大神来了,留下你的代码吧。分虽然不多。但别嫌弃啊。
[解决办法]
select Id,name from(
select B.stano as Id ,A.deptname as name from dept A inner join stainfo B on A.stano=B.stano
union all
select B.deptcode as Id,C.names as name from consumes C inner join dept B on C.deptcode=B.deptcode
union all
select B.stano as Id,D.doorname as name from y_mj_doors D inner join stainfo B on D.stano=B.sta
union all
select B.stano as Id,B.staname as name from stainfo B
)E