尝试在GridView
. 从下面的代码中,单击“编辑”后,我可以选择更改“KPI”名称和“当前目标”。但是,一旦我单击“更新”,就会收到一条错误消息:
'nvarchar' 附近的不正确的 sysntax
这是我的标记:
<p>
<br />
<asp:DropDownList ID="GroupSelection" runat="server" DataSourceID="Group" DataTextField="FcstGroup"
DataValueField="FcstGroup">
</asp:DropDownList>
</p>
<p>
<asp:GridView ID="GridView2" runat="server" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" />
</Columns>
</asp:GridView>
</p>
<p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:WFMConnectionString3 %>"
SelectCommand="select
case _parameter.name as KPI,
[target]*100 as [Current Target]
from _parameter inner join _reporting_group
on _parameter.reporting_group = _reporting_group.id
where _reporting_group.name = @WG "
UpdateCommand="update _parameter set target = .80
where reporting_group = (select ID from _reporting_group where name = @WG)
and name = 'nco_i_e' ">
<SelectParameters>
<asp:ControlParameter ControlID="GroupSelection" Name="WG" PropertyName="SelectedItem.text" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter ControlID="GroupSelection" Name="WG" PropertyName="SelectedItem.text" />
</UpdateParameters>
</asp:SqlDataSource>
</p>
<asp:SqlDataSource ID="Group" runat="server" ConnectionString="<%$ ConnectionStrings:WFMConnectionString3 %>"
SelectCommand=" SELECT distinct _reporting_group.name AS FcstGroup
FROM dbo._metrics INNER JOIN
dbo._reporting_group ON dbo._metrics.reporting_group = dbo._reporting_group.id ">
</asp:SqlDataSource>
我猜问题出在更新命令上,但是在 SQL 中运行时它可以正常工作:
UpdateCommand="update _parameter set target = .80
where reporting_group = (select ID from _reporting_group where name = @WG)
and name = 'nco_i_e' ">
请注意,目前,更新命令仅使用固定设置的“目标”值和固定的“名称”值。最终,我需要使用“当前目标”中输入的值和 KPI 值。但是,一旦我弄清楚为什么会收到“nvarchar”错误消息,我就会解决这个问题。
如果有人能发现问题出在哪里,我将不胜感激。