gridview中nvarchar错误附近的语法不正确 [英] incorrect syntax near nvarchar error in gridview
本文介绍了gridview中nvarchar错误附近的语法不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有关于更新gridview列的问题;当我尝试更新字段时,我收到此错误:
'nvarchar'附近的语法不正确。
必须声明标量变量@ pid。
这是我的一段代码:
< ; asp:GridView ID =GridView1runat =servername =gdHeight =100px
Width =435pxAutoGenerateColumns =FalseDataKeyNames =pidDataSourceID =SqlDataSource1>
< Columns>
< asp:CommandField ShowEditButton =TrueShowSelectButton =True/>
< asp:BoundField DataField =pidHeaderText =pid
SortExpression =pidReadOnly =True/>
< asp:BoundField DataField =nameHeaderText =name
SortExpression =name/>
< asp:BoundField DataField =hoghoghe rozaneHeaderText =hoghoghe rozane
SortExpression =hoghoghe rozane/>
< asp:BoundField DataField =payeHeaderText =paye
SortExpression =paye/>
< \Columns>
< asp:GridView>
< asp:SqlDataSource ID =SqlDataSource1runat =server
ConnectionString =<%$ ConnectionStrings:ConnectionString%>
UpdateCommand =UPDATE [post] SET [name] = @ name,[hoghoghe rozane] = @hoghoghe_rozane,[paye] = @paye WHERE(pid = @pid)>
< UpdateParameters>
< asp:参数名称=名称类型=字符串/>
< asp:参数名称=hoghoghe_rozaneType =Int32/>
< asp:参数名称=payeType =Int32/>
< asp:参数名称=pidType =String/>
< / UpdateParameters>
< / asp:SqlDataSource>
解决方案
ConnectionStrings:ConnectionString%>
UpdateCommand =UPDATE [post] SET [name] = @ name,[hoghoghe rozane] = @hoghoghe_rozane,[paye] = @paye WHERE(pid = @pid)>
< UpdateParameters>
< asp :Parameter Name =nameType =String/>
< asp:Parameter Name =hoghoghe_rozaneType =Int32/>
< asp:Parameter Name =paye Type =Int32/>
< asp:参数名称=pid类型=字符串/>
< / UpdateParameters>
< / asp:SqlDataSource> ;
点击此处: http: //msdn.microsoft.com/en-us/library/ms972948.aspx [ ^ ]。
您应该看到的是,在更新过程中,您有原创和一个领域的新价值。您必须重新填写pid
的原始值。试试这个:
更新 [post] SET [name] = @ name ,[hoghoghe rozane] = @ hoghoghe_rozane ,[paye] = < span class =code-sdkkeyword> @ paye WHERE (pid = @ 原始_ pid)
我猜这是DataType
冲突。
这意味着DataBase中的
与您发送的数据不同。pid
的DataType
由于名称是pid
,它可能是整数
类型,您发送的类型是字符串
。我可能错了。
因此,请检查DataBase <中
DataType
的内容/ code>
I have a problem about the updating a column of my gridview; when I try to update the field I get this error:
Incorrect syntax near 'nvarchar'.
Must declare the scalar variable "@pid".
Here is a piece of my code:
<asp:GridView ID="GridView1" runat="server" name="gd" Height="100px" Width="435px" AutoGenerateColumns="False" DataKeyNames="pid" DataSourceID="SqlDataSource1" > <Columns> <asp:CommandField ShowEditButton="True" ShowSelectButton="True" /> <asp:BoundField DataField="pid" HeaderText="pid" SortExpression="pid" ReadOnly="True" /> <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" /> <asp:BoundField DataField="hoghoghe rozane" HeaderText="hoghoghe rozane" SortExpression="hoghoghe rozane" /> <asp:BoundField DataField="paye" HeaderText="paye" SortExpression="paye" /> <\Columns> <asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" UpdateCommand="UPDATE [post] SET [name] = @name, [hoghoghe rozane] = @hoghoghe_rozane, [paye] = @paye WHERE (pid = @pid)" > <UpdateParameters> <asp:Parameter Name="name" Type="String" /> <asp:Parameter Name="hoghoghe_rozane" Type="Int32" /> <asp:Parameter Name="paye" Type="Int32" /> <asp:Parameter Name="pid" Type="String" /> </UpdateParameters> </asp:SqlDataSource>
解决方案
ConnectionStrings:ConnectionString %>" UpdateCommand="UPDATE [post] SET [name] = @name, [hoghoghe rozane] = @hoghoghe_rozane, [paye] = @paye WHERE (pid = @pid)" > <UpdateParameters> <asp:Parameter Name="name" Type="String" /> <asp:Parameter Name="hoghoghe_rozane" Type="Int32" /> <asp:Parameter Name="paye" Type="Int32" /> <asp:Parameter Name="pid" Type="String" /> </UpdateParameters> </asp:SqlDataSource>
Check here: http://msdn.microsoft.com/en-us/library/ms972948.aspx[^].
What you should have seen is, that during update, you have original and new value of a field. You have to refferre the original value ofpid
. Try this:
UPDATE [post] SET [name] = @name, [hoghoghe rozane] = @hoghoghe_rozane, [paye] = @paye WHERE (pid = @original_pid)
I guess it is aDataType
conflict.
That means theDataType
ofpid
in DataBase is different from the data you are sending.
As the name ispid
, it may be of typeinteger
and the type you are sending isstring
. I may be wrong.
So, check once what areDataType
inDataBase
.
这篇关于gridview中nvarchar错误附近的语法不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文