| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 516 人关注过本帖
标题:[求助] 查询思想是不是出现问题?
取消只看楼主 加入收藏
bavfhpdn66
Rank: 1
等 级:新手上路
威 望:1
帖 子:72
专家分:0
注 册:2007-4-11
收藏
 问题点数:0 回复次数:3 
[求助] 查询思想是不是出现问题?

请教高人一下:我下面这段用来“查询”的代码
为什么不是我想要结果!
难道是我的编程思想出了故障?
protected void btnselect_Click(object sender, EventArgs e)
{
string condition = "";//定义一个变量,用来查询的条件;
if (this.chkID.Checked)//通过数据表的ID来查询
{
if (this.chkID.Text == "")
{
condition = "pID like '%'";
}
else
{
condition =Convert.ToString("pID" ==this.txtID.Text);//把我想要查询ID添在“textbox”控件里且“checkbox”为真
}
}
else
{
condition = "pID like '%'";
}
if (this.chkname.Checked)
{
condition += " and personName like '%" + this.txtname.Text + "%'";
}
if (this.chksex.Checked)
{
if (this.rBtnNan.Checked)
{
condition += " and personSex='男'";
}
else
{
condition += " and personSex='女'";
}
}
DataView dv = new DataView(personoperat.selectAllPerson());
dv.RowFilter = condition;
dv.Sort = "pID Desc";
this.GridView1.DataSource = dv;
this.GridView1.DataBind();

}
}
谢谢!

搜索更多相关主题的帖子: 思想 查询 
2007-04-24 02:58
bavfhpdn66
Rank: 1
等 级:新手上路
威 望:1
帖 子:72
专家分:0
注 册:2007-4-11
收藏
得分:0 

呵呵
有啊
这是其中一部

下面这个就是操作类代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// personoperat 的摘要说明
/// </summary>
public class personoperat
{
public personoperat()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static SqlConnection creatercon()
{return new SqlConnection("server=.;database=adonettest;uid=sa;pwd=;");
}
public static bool findPerson(string pID)
{
SqlConnection con = personoperat.creatercon();
con.Open();
SqlCommand cmd=new SqlCommand("select count(*) from person where pID='"+pID+"'",con);
int count=Convert.ToInt32(cmd.ExecuteScalar());
if(count>0)
{return true;
}
else
{return false;
}
}
public static DataTable selectAllPerson()
{
SqlConnection con = personoperat.creatercon();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from person", con);
DataSet ds = new DataSet();
sda.Fill(ds, "person");
return ds.Tables["person"];
}
public static bool insertOperate(person p)
{ try
{
SqlConnection con = personoperat.creatercon();
con.Open();
SqlCommand cmd= new SqlCommand("insert into person values(@pID,@pName,@pSex)",con);
SqlParameter para=new SqlParameter("@pID",SqlDbType.VarChar,10);
para.Value=p.pID;
cmd.Parameters.Add(para);
para=new SqlParameter("@pName",SqlDbType.VarChar,20);
para.Value=p.pName;
cmd.Parameters.Add(para);
para=new SqlParameter("@pSex",SqlDbType.VarChar,2);
para.Value=p.pSex;
cmd.Parameters.Add(para);
cmd.ExecuteNonQuery();
return true;
}
catch(Exception e)
{return false;
}

}
public static bool updataOperate(person p)
{
try
{ SqlConnection con=personoperat.creatercon();
con.Open();
SqlCommand cmd=new SqlCommand("updata person set personName='"+p.pName+"',personSex='"+p.pSex+"' where pID='"+p.pID+"'",con);
cmd.ExecuteNonQuery();
return true;
}
catch(Exception e)
{return false;
}
}
public static bool delOperate(string pID)
{
try
{
SqlConnection con = personoperat.creatercon();
con.Open();
SqlCommand cmd = new SqlCommand("delect from person where pID='" + pID + "'", con);
cmd.ExecuteNonQuery();
return true;
}
catch(Exception e)
{
return false;
}
}
}


奋起直追,犹未晚也!
2007-04-24 12:39
bavfhpdn66
Rank: 1
等 级:新手上路
威 望:1
帖 子:72
专家分:0
注 册:2007-4-11
收藏
得分:0 

还是不行
郁闷


奋起直追,犹未晚也!
2007-04-24 12:58
bavfhpdn66
Rank: 1
等 级:新手上路
威 望:1
帖 子:72
专家分:0
注 册:2007-4-11
收藏
得分:0 

呵呵
谢谢楼上的“爱编程的小猪”
你的QQ号码多少?


奋起直追,犹未晚也!
2007-04-24 19:24
快速回复:[求助] 查询思想是不是出现问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016397 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved