datagrid update command does not work? Am I missing something?
I am using Datagrid and SQLDataSource to bind data from just one table. In order to enable update, I have write update query which I wrong like this.
update mytable field1=@field1, field2=@field2 where ID=@ID
When I click edit, i get into edit mode. When I submit a change, the change is not submitted and I get no error. Do I need to change something somewhere else? I did not modify any C# code in this example.
Edit: If I omit where ID=@ID, then the whole column is successfully changed but it does not work with ID=@ID. What is wrong here?
Edit: Code
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
SelectCommand="SELECT [my_id], [ID], [FirstName], [LastName], [ApplicationUserName] FROM [member_tbl]"
UpdateCommand="UPDATE [member_tbl] SET [my_id] = @my_id, [FirstName] = @FirstName, [LastName] = @LastName, [ApplicationUserName] = @ApplicationUserName where ID = @ID">
<UpdateParameters>
<asp:Parameter Name="my_id" Type="Int32"/>
<asp:Parameter Name="FirstName" />
开发者_开发问答 <asp:Parameter Name="LastName" />
<asp:Parameter Name="ApplicationUserName" />
<asp:Parameter Name="id" />
</UpdateParameters>
</asp:SqlDataSource>
Answering myself: I found that in order for this to work, the ID column must be the primary key (or may be unique column), otherwise it will not work and wont give you any error, which is a bit strange.
精彩评论