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

请教高人一下:我下面这段用来“查询”的代码
为什么不是我想要结果!
难道是我的编程思想出了故障?
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
cyyu_ryh
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:1899
专家分:176
注 册:2006-10-21
收藏
得分:0 
没SQL语句,这样也可以查询吗

有事无事都密我. MSN: cyyu_ryh@hotmail.co.jp E-mail: cyyu_ryh@
2007-04-24 11:44
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
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 

定义的时候加个 condition = "1=1"试试.


飘过~~
2007-04-24 12:54
bavfhpdn66
Rank: 1
等 级:新手上路
威 望:1
帖 子:72
专家分:0
注 册:2007-4-11
收藏
得分:0 

还是不行
郁闷


奋起直追,犹未晚也!
2007-04-24 12:58
cyyu_ryh
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:1899
专家分:176
注 册:2006-10-21
收藏
得分:0 
不知道是不是condition 在连接SQL语句的时候出了错

有事无事都密我. MSN: cyyu_ryh@hotmail.co.jp E-mail: cyyu_ryh@
2007-04-24 13:05
爱编程的小猪
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2006-2-14
收藏
得分:0 

public SqlConnection openCon()
{
DBConnect = System.Configuration.ConfigurationSettings.AppSettings["ConnectString"];
con = new SqlConnection(DBConnect);
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
}
catch (SqlException ex)
{
Console.WriteLine(ex.Message);
}

return con;
}
public void closeCon()
{
try
{
if (openCon().State== ConnectionState.Open)
{
con.Close();
}
}
catch (SqlException ex)
{
Console.WriteLine(ex.Message);
}
}
--------------------------------------------------------------------------
public DataSet likeDs(String str)
{
Class_Connect mycon=new Class_Connect();
con=mycon.openCon();
SqlCommand cmd=new SqlCommand("select_like",con);
cmd.CommandType=CommandType.StoredProcedure;
cmd.Parameters.Add("@Name",SqlDbType.NVarChar);
cmd.Parameters["@Name"].Value=str;
cmd.Parameters.Add("@Rowcount", SqlDbType.Int);
cmd.Parameters["@Rowcount"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
if (ds != null)
{
sda.Fill(ds, "batle02");
}
return ds;
}
-------------------------------------------------------------------------------
ALTER PROCEDURE select_like
@Name Nvarchar(40)=null,
@Rowcount INT=null OUTPUT
AS
begin
select 产品名称,单位数量,单价,库存量,中止 from 产品 where 产品名称 like '%'+@Name+'%' SET @Rowcount=@@ROWCOUNT
end


-------------------------------------------------------------------------------
protected void Button1_Click(object sender, EventArgs e)
{
string str = null;
str = this.TextBox1.Text.ToString();
Class_Select slt = new Class_Select();
ds = slt.likeDs(str);
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
Class_Connect mycon = new Class_Connect();
mycon.closeCon();

}


2007-04-24 17:01
爱编程的小猪
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2006-2-14
收藏
得分:0 
功能和你类似的呵呵。

2007-04-24 17:03
bavfhpdn66
Rank: 1
等 级:新手上路
威 望:1
帖 子:72
专家分:0
注 册:2007-4-11
收藏
得分:0 

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


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



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

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