有无语法错误,帮我改改谢谢using System;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using Sys
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/07 21:45:52
有无语法错误,帮我改改谢谢using System;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using Sys
有无语法错误,帮我改改谢谢
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Globalization;
using System.Data.SqlClient;
public partial class fileSelect:System.Web.UI.Page
{
string connStr=ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection sqlConn;
SqlCommand sqlComm;
protected void Page_Load(object sender,EventArgs e)
{
if(!IsPostBack)
bind() ;
}
public void bind()
{
sqlConn=new SqlConnection(connStr);
sqlConn.Open();
string sqlstr="selected * from table where 1=1";
if(CB_title.Selected)
{
TB_title.Enabled=true;
sqlstr+="and fileTitle='"%+TB_title.Text%"'";
TB_title.Enabled=false;
}
if(CB_office.Selected)
{
sqlstr+="and fileOffice='"+DDL_office.SelectedItem+"'";
}
if(CB_year.Selected)
{
sqlstr+="and fileYear='"+DDL_year.SelectedItem+"'";
}
if(CB_date.Selected)
{
DateTime startDate=(DateTime)"'"+TB_dateMin.Text+"'";
DateTime endDate=(DateTime)"'"+TB_dateMax.Text+"'";
startDate.ToString("yyyy-mm-dd",DateTimeFormatInfo.InvariantInfo);
starDate.ToString("yyyy-mm-dd",DateTimeFormatInfo.InvariantInfo);
sqlstr+="and reciveDate='"convert(varchar(10),reciveDate,120) between startDate and endDate"'";
}
if(CB_fileWord.Selected)
{
sqlstr+="and 文件字='"+DDL_fileWord.SelectedItem+"'";
}
if(CB_no.Selected)
{
TB_noMin.Enabled=true;
TB_noMax.Enabled=true;
sqlstr+="and receiveNo='"BETWEEN +TB_noMin.Text AND +TB_noMax.Text"'";
TB_noMin.Enabled=false;
TB_noMax.Enabled=false;
}
if(CB_secretLevel.Selected)
{
sqlstr+="and secretLevel='"+DDL_secretLevel.SelectedItem+"'";
}
if(CB_emergency.Selected)
{
sqlstr+="and emergency='"+DDL_emergency.SelectedItem+"'";
}
sqlComm=new sqlCommand(sqlStr,sqlConn);
sqlComm.ExecuteNonQuery();
sqlConn.Close();
bind();
}
}
有无语法错误,帮我改改谢谢using System;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using Sys
1.所有的and前应该加个空格,否则会和上面的语句拼在一起
比如
sqlstr+="and fileTitle='"%+TB_title.Text%"'";
应该修改为
sqlstr+=" and fileTitle='"%+TB_title.Text%"'";
2.时间这里处理有问题,变量不能包括在双引号里面
if(CB_date.Selected)
{
DateTime startDate=(DateTime)"'"+TB_dateMin.Text+"'";
DateTime endDate=(DateTime)"'"+TB_dateMax.Text+"'";
startDate.ToString("yyyy-mm-dd",DateTimeFormatInfo.InvariantInfo);
starDate.ToString("yyyy-mm-dd",DateTimeFormatInfo.InvariantInfo);
sqlstr+="and reciveDate='"convert(varchar(10),reciveDate,120) between startDate and endDate"'";
}
可以修改为
if(CB_date.Selected)
{
sqlstr+= string.Format(" and reciveDate between '{0}' and '{1}'",TB_dateMin.Text,TB_dateMax.Text);
}