gridview中nvarchar附近的语法不正确

时间:2013-05-04 15:59:10

标签: asp.net gridview

我有关于更新gridview列的问题;当我尝试更新字段时,我收到此错误:

  

'nvarchar'附近的语法不正确。
  必须声明标量变量“@pid”。

这是我的一段代码:

<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>

1 个答案:

答案 0 :(得分:1)

将其解决:same problem

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

更新:::

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

试试这段代码:

<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>

希望这会奏效。