2014年7月13日 星期日

[RESOLVED] Error delete and edit in gridview


i am writing a code below which is used in my gridview (asp.net+vb web with access database)


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

SelectCommand="SELECT * FROM [Tasks]"
DeleteCommand="delete [Tasks] where id=@id"

UpdateCommand="update [Tasks] set TaskDescription=@TaskDescription,StartDate=StartDate,EndDate=@EndDate,Notes=@Notes where id=@id"
ProviderName="<%$ ConnectionStrings:baijuepConnectionString.ProviderName %>">












when i click edit button in my gridview and ammend something and press update the data is not updated


and the delete button gives eror as


Syntax error (missing operator) in query expression '[Tasks] where id=@id'.








I think your Update "parameters" section needs to include the "ID" variable, as in;









I don't see anything in the Delete mechanism that could be causing an error, so maybe the missing ID in the Update is failing over to the Delete event.



But, try repairing the Update Parameter, and see if that helps.





added ID in update parameter still not updating



Did you really want StartDate=StartDate in your UpdateCommand?  Also, if I recall correctly, use a ? instead of @ to pass parameters in Access, so try:


UpdateCommand="update  [Tasks] set TaskDescription = ?, StartDate = ?, EndDate= ?, Notes = ? where id = ?"


 



Also, why are you using an SQLDataSource, instead of an AccessDataSource?


  DataFile="~/myAccessDatabase.mdb"
SelectCommand="SELECT * FROM [Tasks]"
DeleteCommand="delete [Tasks] where id=?"
UpdateCommand="update [Tasks] set TaskDescription = ?, StartDate = ?, EndDate= ?, Notes = ? where id = ?"













i changed as per ur direction


edit update works fine but delete gives following error


Syntax error (missing operator) in query expression '[Tasks] where id=?'.






Try:


DeleteCommand="delete FROM [Tasks] where id = ?"

I'm not sure if you need the *, like delete * FROM [Tasks] where id = ?


 


沒有留言:

張貼留言