SQL编辑 - 必须声明标量变量“@ appname”请帮忙 [英] SQL edit - Must declare the scalar variable "@appname" please help

查看:83
本文介绍了SQL编辑 - 必须声明标量变量“@ appname”请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如果有人能帮我解决这个恼人的问题,我将非常感激。我的ASP.NET页面中有一个GridView,它从名为orderlines的数据库表中获取数据,目的是让用户编辑数据并将更改保存到数据库中。 删除链接工作正常,从表中删除数据行,但当我尝试进行更改并单击更新时,我总是收到错误消息

必须声明标量变量@ appname。

有谁能告诉我为什么会这样,并建议修复好吗?我已经阅读了很多关于这个问题的其他论坛,到目前为止还没能解决。

这是我的代码:



Hello all,
If anyone could help me out with this annoying problem I would be extremely grateful. I have got a GridView in my ASP.NET page which takes data from a database table called "orderlines", with the goal of letting the user edit the data and save the changes to the database. The "Delete" link works fine, deleting the row of data from the table, but when I try to make a change and click update I always get the error message
"Must declare the scalar variable "@appname"."
Can anyone tell me why this is happening and suggest a fix please? I've read lots of other forums about this problem and haven't been able to fix it so far.
Here's my code:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="lineid"

                        DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display.">
 <Columns>
  <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
  <asp:BoundField DataField="lineid" HeaderText="lineid" ReadOnly="True" 

          SortExpression="lineid" InsertVisible="False" />
  <asp:BoundField DataField="appname" HeaderText="appname" SortExpression="appname" />
  <asp:BoundField DataField="cost" HeaderText="cost" SortExpression="cost" 

          DataFormatString="{0:c2}" HtmlEncode="False" />
  <asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" />
 </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"

 DeleteCommand="DELETE FROM [orderlines] WHERE [lineid] = ?" InsertCommand="INSERT INTO [orderlines] ([lineid], [appname], [cost], [Quantity]) VALUES (?, ?, ?, ?)"

 ProviderName="<%$ ConnectionStrings:ConnectionString1.ProviderName %>" SelectCommand="SELECT [lineid], [appname], [cost], [Quantity] FROM [orderlines] WHERE ([orderno] = ?)"

 UpdateCommand="UPDATE [orderlines] SET [appname] = @appname, [cost] = @cost, [Quantity] = @Quantity WHERE ([lineid] = @lineid)">
 <DeleteParameters>
  <asp:Parameter Name="lineid" Type="Int16" />
 </DeleteParameters>
 <InsertParameters>
  <asp:Parameter Name="lineid" Type="Int16" />
  <asp:Parameter Name="appname" Type="String" />
  <asp:Parameter Name="cost" Type="Decimal" />
  <asp:Parameter Name="Quantity" Type="Int32" />
 </InsertParameters>
 <SelectParameters>
  <asp:QueryStringParameter Name="orderno" QueryStringField="id" Type="Int16" />
 </SelectParameters>
 <UpdateParameters>
  <asp:Parameter Name="appname" Type="String" />
  <asp:Parameter Name="cost" Type="Decimal" />
  <asp:Parameter Name="Quantity" Type="Int32" />
  <asp:Parameter Name="lineid" Type="Int16" />
 </UpdateParameters>
</asp:SqlDataSource>





谢谢,

Thomas



Thank you,
Thomas

推荐答案

ConnectionStrings:ConnectionString1 %>

DeleteCommand = DELETE FROM [orderlines] WHERE [lineid] =? InsertCommand = INSERT INTO [orderlines]([lineid],[appname],[cost],[Quantity])VALUES(?,?,?, ?)

ProviderName = <%
ConnectionStrings:ConnectionString1 %>" DeleteCommand="DELETE FROM [orderlines] WHERE [lineid] = ?" InsertCommand="INSERT INTO [orderlines] ([lineid], [appname], [cost], [Quantity]) VALUES (?, ?, ?, ?)" ProviderName="<%


ConnectionStrings:ConnectionString1.ProviderName% > SelectCommand = SELECT [lineid],[appname],[cost],[Quantity] FROM [orderlines] WHERE([orderno] =?)

UpdateCommand = UPDATE [orderlines] SET [appname] = @appname,[cost ] = @cost,[数量] = @Quantity WHERE([lineid] = @lineid) >
< DeleteParameters >
< asp:参数 名称 = lineid 类型 = Int16 < span class =code-keyword> / >
< / DeleteParameters >
< InsertParameters >
< asp:参数 名称 = lineid 类型 = < span class =code-keyword> Int16 / >
< asp:参数 名称 = appname 类型 = 字符串 / >
< asp:Paramet呃 名称 = 费用 类型 = 十进制 / >
< asp:参数 名称 = 数量 类型 < span class =code-keyword> = Int32 / >
< / InsertParameters >
< < span class =code-leadattribute> SelectParameters >
< asp:QueryStringParameter 名称 = orderno QueryStringField = id 类型 = Int16 / >
< span class =code-keyword>< / SelectPa rameter >
< UpdateParameters >
< asp:参数 名称 = appname 类型 < span class =code-keyword> = 字符串 / >
< asp:参数 名称 = 费用 类型 = 十进制 / >
< asp:参数 名称 = 数量 类型 = Int32 / >
< span class =code-keyword>< asp:参数 名称 = lineid 类型 = Int16 / > ;
< / UpdateParameters >
< / asp:SqlDataSource >
ConnectionStrings:ConnectionString1.ProviderName %>" SelectCommand="SELECT [lineid], [appname], [cost], [Quantity] FROM [orderlines] WHERE ([orderno] = ?)" UpdateCommand="UPDATE [orderlines] SET [appname] = @appname, [cost] = @cost, [Quantity] = @Quantity WHERE ([lineid] = @lineid)"> <DeleteParameters> <asp:Parameter Name="lineid" Type="Int16" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="lineid" Type="Int16" /> <asp:Parameter Name="appname" Type="String" /> <asp:Parameter Name="cost" Type="Decimal" /> <asp:Parameter Name="Quantity" Type="Int32" /> </InsertParameters> <SelectParameters> <asp:QueryStringParameter Name="orderno" QueryStringField="id" Type="Int16" /> </SelectParameters> <UpdateParameters> <asp:Parameter Name="appname" Type="String" /> <asp:Parameter Name="cost" Type="Decimal" /> <asp:Parameter Name="Quantity" Type="Int32" /> <asp:Parameter Name="lineid" Type="Int16" /> </UpdateParameters> </asp:SqlDataSource>





谢谢,

Thomas



Thank you,
Thomas


UpdateCommand已命名SQL参数名称,其中InsertCommand,SelectCommand和DeleteCommand未命名。



尝试更改:

UpdateCommand has named SQL parameter names, where InsertCommand, SelectCommand and DeleteCommand has unnamed.

Try change:
UPDATE [orderlines] SET [appname] = @appname, [cost] = @cost, [Quantity] = @Quantity WHERE ([lineid] = @lineid)






To

UPDATE [orderlines] SET [appname] = ?, [cost] = ?, [Quantity] = ? WHERE ([lineid] = ?)


这篇关于SQL编辑 - 必须声明标量变量“@ appname”请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆