这也许是本人在论坛上发表的第一篇有深度有内涵的贴子了,使得帅气的我增添一点点成熟的魅力,(扯淡)
帮忙看看
_______________________________________________________________________
当我单击更新或删除时IE说:
UPDATE 语句的语法错误。
程序如下:
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.oledb"%>
<script language="vb" runat="server">
sub page_load(sender 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("../wwwlink.mdb"))
dim texsitename,texurl,texintro,texgrade as textbox
texsitename=e.item.cells(3).controls(0)
texurl=e.item.cells(4).controls(0)
texintro=e.item.cells(5).controls(0)
texgrade=e.item.cells(6).controls(0)
dim sql as string
sql="update wwwlink set sitename='" & texsitename.text & "',url='" & texurl.text & "',intro='" & texintro.text & "',grade='" & texgrade.text & "', where sitename=" & mydatagrid.datakeys(e.item.itemindex)
dim cmd as new oledbcommand(sql,conn)
conn.open()
cmd.executenonquery()
conn.close()
mydatagrid.edititemindex=-1
call binddata()
end sub
sub mydatagrid_delete(sender as object,e as datagridcommandeventargs)
dim conn as new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("../wwwlink.mdb"))
dim cmd as new oledbcommand("delete from wwwlink where sitename=" & mydatagrid.datakeys(e.item.itemindex),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("../wwwlink.mdb"))
dim cmd as new oledbcommand("select * from wwwlink",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 bgcolor="#33FF00">
<h3><font color="#6633FF"><div align="center">网络导航</div></font></h3>
<a href="5-8.aspx" ><div align="center">插入记录</div></a>
<form runat="server">
<asp:datagrid id="mydatagrid" align="center" backcolor="#33FFFF" headerstyle-backcolor="#9900FF" oneditcommand="mydatagrid_edit" oncancelcommand="mydatagrid_cancel" onupdatecommand="mydatagrid_update" ondeletecommand="mydatagrid_delete" datakeyfield="sitename" runat="server">
<columns>
<asp:editcommandcolumn edittext="编辑" updatetext="更新" canceltext="取消" itemstyle-wrap="false"/>
<asp:buttoncolumn text="删除" commandname="delete" itemstyle-wrap="false"/>
</columns>
</asp:datagrid>
</form>
</body>
</html>
[此贴子已经被作者于2007-3-28 16:40:55编辑过]