0
votes

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

1 Answers

1
votes

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.