本人初学。代码如下:
数据库为 :create table person
(
pID varchar(10) primary key,
personName varchar(20) not null,
personSex varchar(2)
)person.cs中定义实体类(这个不管它)
public class person
{ public string pID;
public string pName;
public string pSex;
public person()
}personOperate.cs中主要放一些关于数据库的操作(增加删除修改查询等)
public static SqlConnection createCon()
{ //建立Connection连接对象
return new SqlConnection("server=ysx;database=adoNetTest;uid=sa;pwd=;");
}
public static DataTable selectAllperson()
{ //显示结果
SqlConnection con=personOperate.createCon();
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=new SqlCommand("select * from person",con);
DataSet ds=new DataSet();
sda.Fill(ds,"person");
return ds.Tables["person"];
}在前台查询页面webForm.aspx.cs中事件如下:
private void btnSelect_Click(object sender, System.EventArgs e)
{ //查询事件
string c="";
if(this.ChkPID.Checked) //按pID查询
{
if(this.ChkPID.Text=="")
{
c="pID like '%' ";
}
else
{
c="pID"+this.txtpID.Text;
}
}
else
{
c="pID like '%' ";
}
if(this.ChkName.Checked) //按姓名查询
{
c+=" and personName like'% "+this.txtName.Text+"%'";
}
if(this.ChkSex.Checked) //按性别查询
{
if(this.RbnNan.Checked)
{
c+=" and personSex='男'";
}
else
{
c+=" and personSex='女'";
}
}
DataView dv=new DataView(personOperate.selectAllperson());
dv.RowFilter=c;
dv.Sort="pID DESC";
this.DataGrid1.DataSource=dv;
this.DataGrid1.DataBind();
}
}但是,我只有按性别查询,是成功的。
按pID查询,根本没有反应;按姓名查询,结果是空的。
不报错。
特求助。谢谢。
数据库为 :create table person
(
pID varchar(10) primary key,
personName varchar(20) not null,
personSex varchar(2)
)person.cs中定义实体类(这个不管它)
public class person
{ public string pID;
public string pName;
public string pSex;
public person()
}personOperate.cs中主要放一些关于数据库的操作(增加删除修改查询等)
public static SqlConnection createCon()
{ //建立Connection连接对象
return new SqlConnection("server=ysx;database=adoNetTest;uid=sa;pwd=;");
}
public static DataTable selectAllperson()
{ //显示结果
SqlConnection con=personOperate.createCon();
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=new SqlCommand("select * from person",con);
DataSet ds=new DataSet();
sda.Fill(ds,"person");
return ds.Tables["person"];
}在前台查询页面webForm.aspx.cs中事件如下:
private void btnSelect_Click(object sender, System.EventArgs e)
{ //查询事件
string c="";
if(this.ChkPID.Checked) //按pID查询
{
if(this.ChkPID.Text=="")
{
c="pID like '%' ";
}
else
{
c="pID"+this.txtpID.Text;
}
}
else
{
c="pID like '%' ";
}
if(this.ChkName.Checked) //按姓名查询
{
c+=" and personName like'% "+this.txtName.Text+"%'";
}
if(this.ChkSex.Checked) //按性别查询
{
if(this.RbnNan.Checked)
{
c+=" and personSex='男'";
}
else
{
c+=" and personSex='女'";
}
}
DataView dv=new DataView(personOperate.selectAllperson());
dv.RowFilter=c;
dv.Sort="pID DESC";
this.DataGrid1.DataSource=dv;
this.DataGrid1.DataBind();
}
}但是,我只有按性别查询,是成功的。
按pID查询,根本没有反应;按姓名查询,结果是空的。
不报错。
特求助。谢谢。
解决方案 »
- 模式窗口能否象一般页面使用?
- 如何建立一个外用的sql链接。
- jquery获取列表
- 怎么建立具有检索功能的数据库网站
- Vs2008中文版环境下,JavaScript智能感应不起作用,有谁知道如何解决?
- ?????一个小程序员,不知道怎样选择,在线听大家的意见
- 谁 vs2005 甘特图控件 啊?我要实现网页上的 甘特图,需要c#.net实现的!vs2005 甘特图控件 也行!
- 关于 企业信息系统开发
- 一个这样的错误:未将对象引用设置到对象的实例 还望兄弟姐妹们帮兄弟一把`小的在这谢了
- 各位可以谈谈酒店ERP吗?100分
- 求实现 alert 窗口的效果,但不要alert的那个感叹号
- 这是怎么了呢?
按pID查询,结果显示的是全部记录.
{
c="pID like '%' ";
}
这句有问题的
else
{
c="pID"+this.txtpID.Text; //可能没有取到txtpID.Text,所以按PID查询不了结果
}另外那个if(this.ChkName.Checked) //按姓名查询
{
c+=" and personName like'% "+this.txtName.Text+"%'";
}
可能也写的不对,可是我不会写。。帮忙呀。