c# - An entry with the same key already exists? Gridview -


i have gridview control on page , time try use delete button comes it, gives me error mentioned above. here code:

<asp:gridview id="gridview1" runat="server" autogeneratecolumns="false"      datakeynames="id" datasourceid="accessdatasource1">     <columns>         <asp:commandfield showdeletebutton="true" showeditbutton="true" />         <asp:boundfield datafield="id" headertext="id" insertvisible="false"              readonly="true" sortexpression="id" />         <asp:imagefield dataimageurlfield="picpath"          dataimageurlformatstring="placeimages/{0}" headertext="picture"  controlstyle-cssclass="editphotogridformat">         <controlstyle cssclass="editphotogridformat"></controlstyle>             </asp:imagefield>         <asp:boundfield datafield="picpath" headertext="filename" />         <asp:boundfield datafield="title" headertext="title" sortexpression="title" />         <asp:boundfield datafield="city" headertext="city" sortexpression="city" />         <asp:boundfield datafield="country" headertext="country"              sortexpression="country" />     </columns> </asp:gridview> <asp:accessdatasource id="accessdatasource1" runat="server"      datafile="~/app_data/traveljoansdb.mdb"      deletecommand="delete [slides] [id] = ?"      insertcommand="insert [slides] ([id], [picpath], [title], [city], [country]) values (?, ?, ?, ?, ?)"      selectcommand="select * [slides]"      updatecommand="update [slides] set [picpath] = ?, [title] = ?, [city] = ?, [country] = ? [id] = ?">     <deleteparameters>         <asp:parameter name="id" type="int32" />     </deleteparameters>     <insertparameters>         <asp:parameter name="id" type="int32" />         <asp:parameter name="picpath" type="string" />         <asp:parameter name="title" type="string" />         <asp:parameter name="city" type="string" />         <asp:parameter name="country" type="string" />     </insertparameters>     <updateparameters>         <asp:parameter name="picpath" type="string" />         <asp:parameter name="title" type="string" />         <asp:parameter name="city" type="string" />         <asp:parameter name="country" type="string" />         <asp:parameter name="id" type="int32" />     </updateparameters> </asp:accessdatasource> 

i had problem page had more stuff on gridview. curious if had it, created new page , copied datasource , gridview , still gave me same error. there 9 records in table , there no duplicate pks. id field marked primary key in table. going on?

don't use question mark mentioned in command. please make change below work's fine

deletecommand="delete [slides] [id] = @id"  insertcommand="insert [slides] ([id], [picpath], [title], [city], [country]) values (@id, @picpath, @title, @city, @country)"  selectcommand="select * [slides]"  updatecommand="update [slides] set [picpath] = @picpath, [title] = @title, [city] = @city, [country] = @country [id] = @id"> 

if in case table id having auto increment don't use id in insert command.

deletecommand="delete [slides] [id] = @id"  insertcommand="insert [slides] ([picpath], [title], [city], [country]) values ( @picpath, @title, @city, @country)"  selectcommand="select * [slides]"  updatecommand="update [slides] set [picpath] = @picpath, [title] = @title, [city] = @city, [country] = @country [id] = @id"> 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -