我在做一个模糊查询,但是无论输入什么都,查询的结果都是空!怎么回事呀,希望大家能帮助我一下(小弟刚学)
protected void btn_select_Click(object sender, EventArgs e)
{
SqlConnection conn = new
SqlConnection("Server=.;database=StuManage;uid=sa;pwd=123");//创建链接数据库
conn.Open();//打开数据库
//显示
SqlCommand cmd5 = new SqlCommand("Select*from StuInfo where stuXueyuan like'%" + txt_select.Text + "%' or stuName like'%"
+ txt_select.Text + "%' or stuID like'%" + txt_select.Text + "%' or stuMajor like'%" + txt_select.Text + "%' or stuSex like'%" + txt_select.Text + "%' or stuPhone like'%" + txt_select.Text + "%'", conn);
SqlDataReader sdr1 = cmd5.ExecuteReader();
lbl.Text = "<table border='1'><tr bgcolor='#ABCDEF'><td>姓名</td><td>学号</td> <td>密码</td><td>性别</td> <td>学院</td><td>专业</td><td>班级</td><td>电话</td><td>照片</td></tr>";
while (sdr1.Read())
{
lbl.Text += "<tr>";
lbl.Text += "<td>" + sdr1["stuName"] + "</td>";
lbl.Text += "<td>" + sdr1["stuPwd"] + "</td>";
lbl.Text += "<td>" + sdr1["stuID"] + "</td>";
lbl.Text += "<td>" + sdr1["stuSex"] + "</td>";
lbl.Text += "<td>" + sdr1["stuXueyuan"] + "</td>";
lbl.Text += "<td>" + sdr1["stuMajor"] + "</td>";
lbl.Text += "<td>" + sdr1["stuClass"] + "</td>";
lbl.Text += "<td>" + sdr1["stuPhone"] + "</td>";
lbl.Text += "</tr>";
}
lbl.Text += "</Table>";
sdr1.Close();
//统计人数
string sql = "Select count(*)from StuInfo where stuXueyuan like '%" + txt_select.Text + "%' or stuName like '%"
+ txt_select.Text + "%'or stuID like '%" + txt_select.Text + "%'or stuSex like '%" + txt_select.Text + "%' or stuMajor like '%" + txt_select.Text + "%' or stuPhone like '%" + txt_select.Text + "%' ";//统计出stuID所含个数
SqlCommand cmd6 = new SqlCommand(sql, conn);
lbl_renshu.Text = cmd6.ExecuteScalar().ToString();//在这里给Label的text属性赋值
cmd6.Connection.Close();//关
}
------解决方案--------------------你这查询也太闹心了吧
给你个存储过程
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
--[gjss] 10,20,'a','','','','','',''
ALTER procedure [dbo].[gjss]
(
@startIndex int=1,
@endIndex int=3286,
@ProductName varchar(100)=NULL,
@Inputer varchar(50)=NULL,
@ProductStandard varchar(100)=NULL,
@PriceOriginal varchar(20)=NULL,
@ISBN varchar(20)=NULL,
@CreateTimeStart varchar(20)=NULL,
@CreateTimeEnd varchar(20)=NULL,
@PrintNO varchar(20)=NULL,
@VersionNO varchar(20)=NULL
)
as
SET NOCOUNT ON
begin
declare @start int
declare @end int
declare @SqlWhere varchar(500)
declare @strSql varchar(1000)
declare @strSql1 varchar(1000)
set @start= @startIndex * @endIndex
s