又是后台转前台。后台的SQL在前台怎么写呢??

xinlongyue 2011-03-01 11:52:08
这个是后台写的按键,主要是红字那部分不知道在前台JS中该怎么写~试过很多都抓不到数值
protected void Button3_Click(object sender, EventArgs e)
{
string cbl = " ";
string sqlSelect="";
string sqlFrom="";

for (int i = 0; i < cblCust_id.Items.Count; i++)
{
if (cblCust_id.Items[i].Selected == true)
{

cbl = cblCust_id.Items[i].Value;
sqlSelect += "P" + cbl + ".Stock P" + cbl + ", S" + cbl + ".tr_qty S" + cbl +"";
sqlFrom += " left join pd120 P" + cbl + " on P" + cbl + ".item_id=P1.item_id and P" + cbl + ".hou_no='" + cbl + "'"
+ " left join (select item_id,sum(tr_qty)tr_qty from sa395 "
+ " where tr_date>='2011/01/01' and tr_date<'2011/01/01' and substring(sale_id,1,6)='" + cbl + "' "
+ " group by item_id) S"+cbl+" on S"+cbl+".item_id=P1.item_id ";

}
}
if (cbl != "")
{
cbl = cbl.Substring(0, cbl.Length - 1);
Response.Redirect("SaRight.aspx?SelectSql=" + sqlSelect+"&FromSql=" +sqlFrom);
}
else
{
cbl = "空";
Response.Write("<script>alert('选中的值为:" + cbl + "')</script>");
}
}
...全文
185 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2011-03-01
  • 打赏
  • 举报
回复
hiddenfield保存数据
ClientScript.RegisterStartupScript(this.GetType(), "message", " <script language='javascript' >document.getElementById('Hf').value='"+变量+"'; </script>");
cjh200102 2011-03-01
  • 打赏
  • 举报
回复
不知道楼主为什么要这么做??
qiudong_5210 2011-03-01
  • 打赏
  • 举报
回复
不明白为啥要把语句放在前台……
q107770540 2011-03-01
  • 打赏
  • 举报
回复
前台设置一隐藏域
将后台的SQL语句放在隐藏域中

前台利用 document.getElementById("")画获取
xinlongyue 2011-03-01
  • 打赏
  • 举报
回复
辛辛苦苦的。终于弄出来了。。感谢同事的帮吗。
function Button1_onclick()
{
//if (canQuery()==false) return false;
var s1,s2,s3,s4,cbl,sqlSelect,sqlFrom;
sqlSelect = "";
sqlFrom = "";
cbl ="";
s2 = "";
s4 = "";
s1=document.getElementById("txtMcs_no").value;
if (s1!='') s2+=" and P1.mcs_no='"+s1+"'";

s1=document.getElementById("txtHou_no1").value;
if (s1!='') s2+=" and P2.hou_no='"+s1+"'";

s3=document.getElementById("txtDate1").value;
if (s3!='') s4+=" tr_date>=cast('"+s3+"' as date)";

s3=document.getElementById("txtDate2").value;
if (s3!='') s4+=" and tr_date< cast('"+s3+"' as date)+1";

var cblCust_id = document.getElementById("cblCust_id");
var chk=cblCust_id.getElementsByTagName("input");

for (var i = 0; i < chk.length; i++)
{
if(chk[i].type=='checkbox')
{
if (chk[i].checked)
{
cbl = cblCust_id.attributes['chkValue'].value.split(',')[i];


sqlSelect += "P" + cbl + ".Stock P" + cbl + ", S" + cbl + ".tr_qty S" + cbl +"";
sqlFrom += " left join pd120 P" + cbl + " on P" + cbl + ".item_id=P1.item_id and P" + cbl + ".hou_no='" + cbl + "'"
+ " left join (select item_id,sum(tr_qty)tr_qty from sa395 "
+ " where "+s4+" and substring(sale_id,1,6)='" + cbl + "' "
+ " group by item_id) S"+cbl+" on S"+cbl+".item_id=P1.item_id ";
}
}
}
if (cbl!="")
{
cbl = cbl.substr(0, cbl.length - 1);
document.frames("myFrame").location.reload("SaRight.aspx?SelectSql=" + sqlSelect + "&FromSql=" + encodeURIComponent(sqlFrom) + "&dateSQL=" + encodeURIComponent(s4) +"&whereSQL=" + encodeURIComponent(s2));
}
else
{
cbl = "空";
alert("你勾选的号码为"+cbl+"!");
}

为了能抓取到cbl值!!只好在后台多写个方法了~~一下是方法
protected void AddCbl(DataSet DS)
{
string strchkValue = "";
for (int i = 0; i < DS.Tables[0].Rows.Count; i++)
{

strchkValue += DS.Tables[0].Rows[i]["cust_id"].ToString() + ",";
}
strchkValue = strchkValue.TrimEnd(',');

cblCust_id.Attributes.Add("chkValue", strchkValue)
mingl11 2011-03-01
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 xinlongyue 的回复:]
为什么后台转前台。。。嗯。。
因为啊。。。前台比后台快啊。。。
而且还能多学一中方法啊。。。
前后都会了。。那还有什么不会捏~
[/Quote]
学习精神可嘉~~~
shine_fly 2011-03-01
  • 打赏
  • 举报
回复
哥表示鸭梨很大。。。用隐藏域也可以。但比较疑惑SQL语句为什么要写到JS那,建个Header,然后JS把参数传过来,写这里面也好点啊。
xinlongyue 2011-03-01
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wuyq11 的回复:]
hiddenfield保存数据
ClientScript.RegisterStartupScript(this.GetType(), "message", " <script language='javascript' >document.getElementById('Hf').value='"+变量+"'; </script>");
[/Quote]
不懂。。。。。。。。。
xinlongyue 2011-03-01
  • 打赏
  • 举报
回复
为什么后台转前台。。。嗯。。
因为啊。。。前台比后台快啊。。。
而且还能多学一中方法啊。。。
前后都会了。。那还有什么不会捏~
wu_rual123 2011-03-01
  • 打赏
  • 举报
回复
js好像不能直接操作数据库的吧,可以用Ajax获取前台的数值,传递到后台处理嘛
Adechen 2011-03-01
  • 打赏
  • 举报
回复
hiddenfield
说实在还不是太明白楼主意思
hhwei1985 2011-03-01
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wuyq11 的回复:]
hiddenfield保存数据
ClientScript.RegisterStartupScript(this.GetType(), "message", " <script language='javascript' >document.getElementById('Hf').value='"+变量+"'; </script>");
[/Quote].

62,046

社区成员

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

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

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

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