晒太阳的第一个精确查询与模糊查询(zhuan)
晒太阳的第一个精确查询:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(IsPostBack)
{
string role_name = this.Request["role_name"].ToString();
string org_id = this.Request["org_id"].ToString();
string strSQL,strSQL1,strSQL2;
strSQL = "";
strSQL1 = "select * from role";
strSQL2=" order by role_id desc";
if(role_name != "")
{
strSQL=" where role_name='"+ role_name +"'";
}
if(org_id != "")
{
if(strSQL == "")
{
strSQL=" where org_id='"+ org_id +"'";
}
else
{
strSQL=strSQL + " and org_id='"+ org_id +"'";
}
}
strSQL = strSQL1 + strSQL + strSQL2;
//Response.Write(strSQL);
//Response.End();
OracleConnection conn=new OracleConnection("User ID=wos;Password=wos;Data Source=test;");
//OracleDataAdapter cmd=new OracleDataAdapter("select * from role",conn);
OracleDataAdapter cmd=new OracleDataAdapter(strSQL,conn);
DataSet dtSet=new DataSet();
cmd.Fill(dtSet,"table1");
this.role.DataSource=dtSet.Tables["table1"];
this.role.DataBind();
}
}
晒太阳的第一个模糊查询
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(IsPostBack)
{
string role_name = this.Request["role_name"].ToString();
string org_id = this.Request["org_id"].ToString();
string strSQL;
// 模糊查询:
strSQL="select * from role where role_name like '%"+ role_name +"%' and org_id like '%"+ org_id +"%' order by role_id desc";
OracleConnection conn=new OracleConnection("User ID=wos;Password=wos;Data Source=test;");
OracleDataAdapter cmd=new OracleDataAdapter(strSQL,conn);
DataSet dtSet=new DataSet();
cmd.Fill(dtSet,"table1");
this.role.DataSource=dtSet.Tables["table1"];
this.role.DataBind();
}
}