Reputation: 880
Here is a working version of the gridview updatecommand
<asp:SqlDataSource ID="MatchDataSource" runat="server" SelectCommand="SELECT * FROM [dbo].[SYR1]"
UpdateCommand="UPDATE [dbo].[SYR1] SET Fname = @Fname
WHERE ID=@ID
ConnectionString="<%$ ConnectionStrings:ApplicationServices %>">
<UpdateParameters>
<asp:Parameter Type="String" Name="Fname" />
<asp:Parameter Type="String" Name="Lname" />
<asp:Parameter Type="String" Name="ID" />
</UpdateParameters>
</asp:SqlDataSource>
<Columns>
<asp:CommandField ShowEditButton="True"></asp:CommandField>
<asp:BoundField ReadOnly="true" HeaderText="First Name" DataField="fname" SortExpression="fname"><ItemStyle HorizontalAlign="Right"></ItemStyle></asp:BoundField>
<asp:BoundField ReadOnly="false" HeaderText="Last Name" DataField="lname" SortExpression="lname"><ItemStyle HorizontalAlign="Right"></ItemStyle> </asp:BoundField>
</Columns>
The problem I have is I have database columns with 2 names, i.e. instead of "fname" I have "First Name". The datafield is fine and will take a 2 word column name
<asp:BoundField ReadOnly="true" HeaderText="First Name" DataField="First Name" SortExpression="fname"><ItemStyle HorizontalAlign="Right"></ItemStyle></asp:BoundField>
The problem is I cant save a 2 worded parameter so I'm not sure how I get the update to work... Below is an unsuccesful attempt. Can anyone help me out with it please.
UpdateCommand="UPDATE [dbo].[SYR1] SET [First Name] = @First name
WHERE ID=@ID
ConnectionString="<%$ ConnectionStrings:ApplicationServices %>">
<UpdateParameters>
<asp:Parameter Type="String" Name="First Name" />
<asp:Parameter Type="String" Name="Last Name" />
<asp:Parameter Type="String" Name="ID" />
</UpdateParameters>
Upvotes: 0
Views: 1036
Reputation: 19591
Solution one
UpdateCommand="UPDATE [dbo].[SYR1] SET [First Name] = @First name
WHERE ID=@ID
ConnectionString="<%$ ConnectionStrings:ApplicationServices %>">
<UpdateParameters>
<asp:Parameter Type="String" Name="[First Name]" />
<asp:Parameter Type="String" Name="[Last Name]" />
<asp:Parameter Type="String" Name="ID" />
</UpdateParameters>
If it doesn't work, then you can use aliasing,
Solution two
Select [First Name] as Fname, ...
from tableName
Upvotes: 1
Reputation: 16134
Refer link for rules http://msdn.microsoft.com/en-us/library/aa223962.aspx
Embedded spaces or special characters are not allowed.
Change your parameter names:
UpdateCommand="UPDATE [dbo].[SYR1] SET [First Name] = @FirstName
WHERE ID=@ID
ConnectionString="<%$ ConnectionStrings:ApplicationServices %>">
<UpdateParameters>
<asp:Parameter Type="String" Name="FirstName" />
<asp:Parameter Type="String" Name="LastName" />
<asp:Parameter Type="String" Name="ID" />
</UpdateParameters>
Upvotes: 1