_______________________________________________________________________________
Server Error in '/' Application.
Exception Details: System.Data.OleDb.OleDbException: 操作必须使用一个可更新的查询。
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Source Error:
|
____________________________________________________________________
下面是代码部分:
<%@ page debug="true" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.oledb" %>
<script language="vb" runat="server">
sub page_load(sendeer as object,e as eventargs)
if page.ispostback=false then
call binddata()
end if
end sub
sub mydatagrid_edit(sender as object,e as datagridcommandeventargs)
mydatagrid.edititemindex=cint(e.item.itemindex)
call binddata()
end sub
sub mydatagrid_cancel(sender as object,e as datagridcommandeventargs)
mydatagrid.edititemindex=-1
call binddata()
end sub
sub mydatagrid_update(sender as object,e as datagridcommandeventargs)
dim conn as new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("database/wwwlink.mdb"))
dim texsitename,texurl,texintro as textbox
texsitename=e.item.cells(1).controls(0)
texurl=e.item.cells(3).controls(1)
texintro=e.item.cells(2).controls(0)
dim texgrade as dropdownlist
texgrade=e.item.cells(4).controls(1)
dim strsql as string
strsql="update link set sitename='" & texsitename.text & "',url='" & texurl.text & "',intro='" & texintro.text & "' ,grade=" & cint(texgrade.selecteditem.text) & ",submit_date=#" & now() & "# where id=" & mydatagrid.datakeys(cint(e.item.itemindex))
dim cmd as new oledbcommand(strsql,conn)
conn.open()
cmd.ExecuteNonQuery()
conn.close()
mydatagrid.edititemindex=-1
call binddata()
end sub
sub binddata()
dim conn as new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("database/wwwlink.mdb"))
dim cmd as new oledbcommand("select * from link",conn)
dim adp as new oledbdataadapter(cmd)
dim ds as new dataset
adp.fill(ds,"link")
mydatagrid.datasource=ds.tables("link").defaultview
mydatagrid.databind()
end sub
</script>
<HTML>
<BODY>
<h2 align="center">网络导航</h2>
<form runat="server">
<asp:datagrid id="mydatagrid" headerstyle-backcolor="#33FF00" width="90%" oneditcommand="mydatagrid_edit" onupdatecommand="mydatagrid_update" oncancelcommand="mydatagrid_cancel" autogeneratecolumns="false" datakeyfield="id" runat="server">
<columns>
<asp:editcommandcolumn edittext="编辑" updatetext="更新" canceltext="取消" itemstyle-wrap="false"/>
<asp:boundcolumn headertext="网站名称" datafield="sitename" />
<asp:boundcolumn headertext="网站简介" datafield="intro" />
<asp:templatecolumn headertext="网站地址">
<itemtemplate>
<asp:hyperlink text='<%#container.dataitem("url")%>' navigateurl='<%#container.dataitem("url")%>'
target="_blank" runat="server"/>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="url" text='<%#container.dataitem("url")%>' runat="server"/>
</edititemtemplate>
</asp:templatecolumn>
<asp:templatecolumn headertext="网站评分">
<itemtemplate>
<asp:label text='<%#container.dataitem("grade")%>' runat="server"/>
</itemtemplate>
<edititemtemplate>
<asp:dropdownlist id="grade" runat="server">
<asp:listitem>1</asp:listitem>
<asp:listitem>2</asp:listitem>
<asp:listitem selected="true">3</asp:listitem>
<asp:listitem>4</asp:listitem>
<asp:listitem>5</asp:listitem>
</asp:dropdownlist>
</edititemtemplate>
</asp:templatecolumn>
<asp:boundcolumn headertext="提交时间" datafield="submit_date" readonly="true"/>
<asp:boundcolumn headertext="网站编号" datafield="id" readonly="true"/>
</columns>
</asp:datagrid>
</form>
</body>
</html>
</BODY>
</HTML>
[此贴子已经被作者于2007-4-5 18:44:02编辑过]