.aspx的语法已经忘光了.
界面如下

界面代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebRdlc.WebForm1" %>
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<asp:Label ID="Label1" runat="server" Text="供应商名称"></asp:Label>
<asp:TextBox ID="txtGysmc" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="成本隶属地"></asp:Label>
<asp:TextBox ID="txtCblsd" runat="server"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Text="申请时间"></asp:Label>
<asp:TextBox ID="TextBox3" runat="server" Width="81px"></asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server" Width="81px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="查询" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" Height="399px" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Width="978px">
<LocalReport ReportPath="RDLC\Report1.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="SqlDataSource1C" Name="DataSet1" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:SqlDataSource ID="SqlDataSource1C" runat="server" ConnectionString="<%$ ConnectionStrings:DLX_OAConnectionString %>" SelectCommand="SELECT [costcentermark],[lastname], [costcentername], [dlxsort1], [nppd03],[nppd04], [nppd09], [nppd11],[npp04],SUM(nppd10) AS nppd10,SUM(nppd08) AS nppd08 FROM [DLX_NewStatisticsRF0330] GROUP BY nppd11,lastname,costcentermark,costcentername,dlxsort1,nppd03,nppd04,nppd09,npp04 ORDER BY costcentermark"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebRdlc
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
string cblsd = txtCblsd.Text;
string gysmc = txtGysmc.Text;
string sqlcontent = "SELECT [costcentermark],[lastname] [costcentername], [dlxsort1], [nppd03],[nppd04], [nppd09], [nppd11],npp04,SUM(nppd10) AS nppd10,SUM(nppd08) AS nppd08 FROM [DLX_NewStatisticsRF0330] ";
string sqlcountet2 = " GROUP BY nppd11,lastname,costcentermark,costcentername,dlxsort1,nppd03,nppd04,nppd09,npp04 ORDER BY costcentermark";
string wherecontent = " where nppd11 LIKE '%" + gysmc + "%' and dlxsort1 LIKE '%" + cblsd + "%'";
SqlDataSource1C.SelectCommand = sqlcontent + wherecontent + sqlcountet2;
ReportViewer1.LocalReport.Refresh();
}
}
}
我后台是要求 根据我拼接的sql 来查询数据 刷新界面.
但是我的写法肯定是错的.求正确的写法.
------解决思路----------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebRdlc
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
if (String.IsNullOrWhiteSpace(txtGysmc.Text) == true)
{
Response.Write("<script>alert('供应商不能为空');</script>");
return;
}
if (String.IsNullOrEmpty(txtCblsd.Text) == true)
{
Response.Write("<script>alert('成本隶属地不能为空');</script>");
return;
}
if (String.IsNullOrEmpty(txtTimeEnd.Text) == true)
{
Response.Write("<script>alert('申请时间不能空!');</script>");
return;
}
if (String.IsNullOrEmpty(txtTimeStart.Text) == true)
{
Response.Write("<script>alert('申请时间不能空!');</script>");
return;
}
string cblsd = txtCblsd.Text;
string gysmc = txtGysmc.Text;
string timeStart = txtTimeStart.Text;
string timeEnd = txtTimeEnd.Text;
string sqlcontent = "SELECT [costcentermark],[lastname],[costcentername], [dlxsort1], [nppd03],[nppd04], [nppd09], [nppd11],npp04,nppd06,NPP16,SUM(nppd10) AS nppd10,SUM(nppd08) AS nppd08 FROM [DLX_NewStatisticsRF0330] ";
string sqlcountet2 = " GROUP BY nppd11,lastname,costcentermark,costcentername,dlxsort1,nppd03,nppd04,nppd09,npp04,nppd06,NPP16 ORDER BY costcentermark";
string wherecontent = " where nppd11 LIKE '%" + gysmc + "%' and dlxsort1 = '" + cblsd + "'" + " AND npp04 >= '" + timeStart + "' and npp04 <= '" + timeEnd + "'";
SqlDataSource1C.SelectCommand = sqlcontent + wherecontent + sqlcountet2;
//SqlDataSource1C.DataBind();
ReportViewer1.LocalReport.Refresh();
}
}
}
自己参考吧