报where 附近有语法错误,那位帮助解决一下

Rotel-刘志东 2009-03-04 11:49:50
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 WangWei.DBUtility;
using WangWei.DAL;
using System.Data.SqlClient;


public partial class Queryph : WangWei.Common.BasePage
{
string strWhere = "";

protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
try
{
this.DocDate.Text = DateTime.Now.ToShortDateString();
this.EDate.Text = DateTime.Now.ToShortDateString();
strWhere = GetstrWhere();
this.BindData(strWhere);
}
catch (Exception ex)
{
throw ex;
}


}
}

protected void BindData(string where)
{
int count = 0;
string strSql = " select count(1) from ibt1 T0 " + where;
DataSet ds = new DataSet();
ds = WangWei.DBUtility.DbHelperSQLSAP.Query(strSql);

count = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
ds = WangWei.DBUtility.DbHelperSQLSAP.GetListPage(" select T0.itemcode ,T0.itemName ,T2.FrgnName ,T2.SuppcatNum ,T0.Quantity,T0.BatchNum , T4.PrdDate ,T4.ExpDate ,T0.Whscode,T0.BaseEntry,T0.Direction,T0.DocDate from ibt1 T0 left join oitm T2 ON T2.itemcode=T0.itemcode left join owtr T3 ON T3.DocNum=T0.BaseEntry left join oibt T4 ON T4.ItemCode=T0.ItemCode and T4.Whscode=T0.Whscode and T4.BatchNum=T0.BatchNum and T0.Direction='0' and T0.whscode<>'01' and T3.Filler='01' order by T0.BaseEntry ,T0.itemcode asc "
+ where, pager.CurrentPageIndex,pager.PageSize, "itemcode", "itemcode" );

Repeater.DataSource = ds;
Repeater.DataBind();

pager.RecordCount = count;

pager.CustomInfoText = "记录总数:<font color=\"blue\"><b>" + count.ToString() + "</b></font>";
pager.CustomInfoText += " 总页数:<font color=\"blue\"><b>" + pager.PageCount.ToString() + "</b></font>";
pager.CustomInfoText += " 当前页:<font color=\"red\"><b>" + pager.CurrentPageIndex.ToString() + "</b></font>";

}

protected string GetLineID()
{
return this.txtLineID.Text.ToString();
}

protected string GetWhsCode(string strCode)
{
WangWei.Model.Depart m_Depart = new WangWei.Model.Depart();
WangWei.DAL.Depart o_Depart = new WangWei.DAL.Depart();
m_Depart = o_Depart.GetModel(Convert.ToInt32(strCode));
return m_Depart.Store;
}

protected void ChangePage(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
{
pager.CurrentPageIndex = e.NewPageIndex;
strWhere = GetstrWhere();
BindData(strWhere);
}

protected string GetstrWhere()
{
string sql = "";
string str1 = "";
string strBeginDate = "2008-01-01";
string strEndDate = "2100-01-01";

if (this.DocDate.Text != "")
strBeginDate = this.DocDate.Text;
if (this.EDate.Text != "")
strEndDate = this.EDate.Text;

sql = " where T0.Docdate>='" + strBeginDate + "' and T0.docdate<='" + strEndDate + "' ";

if (this.user.Position != "1")
{
sql = sql + " and T0.whscode='" + GetWhsCode(this.user.Depart) + "' ";
}

if (this.DropDownList1.SelectedValue == "All")
{
return sql;
}
if (this.DropDownList2.SelectedValue == "=")
str1 = "=";
if (this.DropDownList2.SelectedValue == ">")
str1 = ">";
if (this.DropDownList2.SelectedValue == "<")
str1 = "<";
if (this.DropDownList2.SelectedValue == "")
str1 = "like ";
if (this.TextBox1.Text == "")
{
AddLoadMessage("请填写参数");
return sql;
}
str1 = this.DropDownList2.SelectedValue;
if (str1.ToLower() == "like")
{
sql = sql + " and " + this.DropDownList1.SelectedValue + " " + this.DropDownList2.SelectedValue + " '%" + this.TextBox1.Text + "%' ";
}
else
{
sql = sql + " and " + this.DropDownList1.SelectedValue + " " + this.DropDownList2.SelectedValue + " '" + this.TextBox1.Text + "' ";
}
return sql;
}

protected void Button1_Click(object sender, EventArgs e)
{
strWhere = GetstrWhere();

BindData(strWhere);


}
}
...全文
203 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zuoming120 2009-03-04
  • 打赏
  • 举报
回复
7楼的是对的。
jimu8130 2009-03-04
  • 打赏
  • 举报
回复
if (this.DropDownList2.SelectedValue == "=")
str1 = "=";
if (this.DropDownList2.SelectedValue == ">")
str1 = ">";
if (this.DropDownList2.SelectedValue == "<")
str1 = "<";
if (this.DropDownList2.SelectedValue == "")
str1 = "like ";
if (this.TextBox1.Text == "")
{
AddLoadMessage("请填写参数");
return sql;
}
str1 = this.DropDownList2.SelectedValue;
if (str1.ToLower() == "like")
{
sql = sql + " and " + this.DropDownList1.SelectedValue + " " + this.DropDownList2.SelectedValue + " '%" + this.TextBox1.Text + "%' ";
}
else
{
sql = sql + " and " + this.DropDownList1.SelectedValue + " " + this.DropDownList2.SelectedValue + " '" + this.TextBox1.Text + "' ";--------看看你认为>,< 是比较字符串的嘛?如果不是请去掉单引号或者更改代码
}
return sql;
--------------------
姑且不说拼接容易导致异常得不到处理容易被sql注入攻击,来说说你的代码的一些问题前面你的strl就已经取得dropdownlist2的选择值了,结果拼接的时候还用去取一次,唉
vrhero 2009-03-04
  • 打赏
  • 举报
回复
string strSql = " select count(1) from ibt1 T0 " + where;
------------------
string strSql = " select count(1) from ibt1 T0 where" +;//把where放到字符串里面去...

ps:不要拼SQL,用Parameter传递参数...
migercai 2009-03-04
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lzd_83 的回复:]
此sql语句在查询分析器没有问题。
SQL codeselect T0.itemcode ,T0.itemName ,T2.FrgnName ,T2.SuppcatNum ,T0.Quantity,T0.BatchNum , T4.PrdDate ,T4.ExpDate ,T0.Whscode,T0.BaseEntry,T0.Direction,T0.DocDate from ibt1 T0
left join oitm T2 ON T2.itemcode=T0.itemcode
left join owtr T3 ON T3.DocNum=T0.BaseEntry
left join oibt T4 ON T4.ItemCode=T0.ItemCode
and T4.Whscode=T0.Whscode and T4.Batch…
[/Quote]
你的sql语句貌似没有where啊?
难道我年纪大了,眼花
zzxap 2009-03-04
  • 打赏
  • 举报
回复
[code=SQL]
ds = WangWei.DBUtility.DbHelperSQLSAP.GetListPage(" select T0.itemcode ,T0.itemName ,T2.FrgnName ,T2.SuppcatNum ,T0.Quantity,T0.BatchNum , T4.PrdDate ,T4.ExpDate ,T0.Whscode,T0.BaseEntry,T0.Direction,T0.DocDate from ibt1 T0 left join oitm T2 ON T2.itemcode=T0.itemcode left join owtr T3 ON T3.DocNum=T0.BaseEntry left join oibt T4 ON T4.ItemCode=T0.ItemCode and T4.Whscode=T0.Whscode and T4.BatchNum=T0.BatchNum and T0.Direction='0' and T0.whscode<>'01' and T3.Filler='01' order by T0.BaseEntry ,T0.itemcode asc "

+ where, pager.CurrentPageIndex,pager.PageSize, "itemcode", "itemcode" );


改为
ds = WangWei.DBUtility.DbHelperSQLSAP.GetListPage(" select T0.itemcode ,T0.itemName ,T2.FrgnName ,T2.SuppcatNum ,T0.Quantity,T0.BatchNum , T4.PrdDate ,T4.ExpDate ,T0.Whscode,T0.BaseEntry,T0.Direction,T0.DocDate from ibt1 T0 left join oitm T2 ON T2.itemcode=T0.itemcode left join owtr T3 ON T3.DocNum=T0.BaseEntry left join oibt T4 ON T4.ItemCode=T0.ItemCode and T4.Whscode=T0.Whscode and T4.BatchNum=T0.BatchNum and T0.Direction='0' and T0.whscode<>'01' and T3.Filler='01' " + where+" order by T0.BaseEntry ,T0.itemcode asc "

, pager.CurrentPageIndex,pager.PageSize, "itemcode", "itemcode" );

应该先+ where 然后再 order by T0.BaseEntry ,T0.itemcode asc

[/CODE]
fangq 2009-03-04
  • 打赏
  • 举报
回复
又遇到一个重来不调试的主儿
Rotel-刘志东 2009-03-04
  • 打赏
  • 举报
回复
此sql语句在查询分析器没有问题。
select T0.itemcode  ,T0.itemName ,T2.FrgnName ,T2.SuppcatNum ,T0.Quantity,T0.BatchNum ,  T4.PrdDate  ,T4.ExpDate ,T0.Whscode,T0.BaseEntry,T0.Direction,T0.DocDate  from ibt1 T0 
left join oitm T2 ON T2.itemcode=T0.itemcode
left join owtr T3 ON T3.DocNum=T0.BaseEntry
left join oibt T4 ON T4.ItemCode=T0.ItemCode
and T4.Whscode=T0.Whscode and T4.BatchNum=T0.BatchNum and
T0.Direction='0' and T0.whscode<>'01' and T3.Filler='01'
order by T0.BaseEntry ,T0.itemcode asc
LifeChina555 2009-03-04
  • 打赏
  • 举报
回复
跟踪一下你合成的sql语句,让把他输出看看
Rotel-刘志东 2009-03-04
  • 打赏
  • 举报
回复
多谢了!!
likevs 2009-03-04
  • 打赏
  • 举报
回复
路过呵呵

以前讨厌别人问问题时不贴代码,现在我发现,贴了代码而代码又太多时,我也很讨厌Y

*O*

楼上几位已说得很明白,祝楼主好运
gaolei477 2009-03-04
  • 打赏
  • 举报
回复
调试看看

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧