2014年7月13日 星期日

[RESOLVED] Gridview update


in my asp.net+vb web with access database. i used the following code. data is displaying correctly but when edit/update is done data is not saved


                    DataSourceID="SqlDataSource1" AutoGenerateEditButton="True">







ConnectionString="<%$ ConnectionStrings:baijuepConnectionString %>"
ProviderName="<%$ ConnectionStrings:baijuepConnectionString.ProviderName %>"

SelectCommand="SELECT [STAFF], [NAME], [COURSE] FROM [STUFF]"
UpdateCommand="UPDATE [STUFF] SET [NAME] = @NAME, [COURSE] = @COURSE WHERE [STAFF] = @STAFF">








I think you need to call 


SqlDataSource1.Update() method  , then it will update records 




Where is your update parameters?


When using updatecommand with parameters, you need to set update parameters







Usualy, updating data with accessdatasource/sqldatasource in gridview we need pimary key to determine which row you want to update


The primary key value passed through datakeynames



And updatecommand and updateparameters looks like this


UpdateCommand="UPDATE [STUFF] SET [NAME] = ?, [COURSE] =?,  [STAFF] = ? WHERE ID=?">
















沒有留言:

張貼留言