在gridview中nvarchar附近的语法不正确 [英] incorrect syntax near nvarchar in gridview

查看:230
本文介绍了在gridview中nvarchar附近的语法不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于更新gridview的列的问题;当我尝试更新字段时,出现以下错误:


'nvarchar'附近语法不正确。

必须声明标量变量@pid。

以下是我的一段代码:

 < asp:GridView ID =GridView1runat =servername =gdHeight =100px
Width =435pxAutoGenerateColumns = FalseDataKeyNames =pidDataSourceID =SqlDataSource1>
<列>
< 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/>
< \栏>
< 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:Parameter Name =nameType =String/>
< asp:Parameter Name =hoghoghe_rozaneType =Int32/>
< asp:Parameter Name =payeType =Int32/>
< asp:Parameter Name =pidType =String/>
< / UpdateParameters>
< / asp:SqlDataSource>


解决方案

chek this out:同样的问题



它说你必须将[hoghoghe rozane]改为[hoghoghe_rozane]



更新:::



1 。确保数据库
2.fields中的pid字段的类型在表格中不应有空格
3.alias不应该有空格

 < asp:GridView ID =GridView1runat =servername =gd Height =100px
Width =435pxAutoGenerateColumns =FalseDataKeyNames =pidDataSourceID =SqlDataSource1>
<列>
< 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 =hoghogheRozane
SortExpression =hoghoghe_rozane/>
< asp:BoundField DataField =payeHeaderText =paye
SortExpression =paye/>
< \栏>






  ConnectionString =<%$ 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 =payeType =Int32/>
< asp:Parameter Name =pidType =String/>
< / UpdateParameters>



希望工作。 / p>

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>

解决方案

chek this out : same problem

it says you must change [hoghoghe rozane] into [hoghoghe_rozane]

Update :::

1.Make sure that the type of pid field in database 2.fields should not have spaces in your tables 3.alias should not have spaces too

try this 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="hoghogheRozane" 
                SortExpression="hoghoghe_rozane" />
    <asp:BoundField DataField="paye" HeaderText="paye" 
                SortExpression="paye" />
<\Columns>

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>

hope that would work.

这篇关于在gridview中nvarchar附近的语法不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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