注册 登录
编程论坛 ASP.NET技术论坛

UPDATE 语句的语法错误

tm_ma 发布于 2007-03-28 16:24, 1645 次点击

这也许是本人在论坛上发表的第一篇有深度有内涵的贴子了,使得帅气的我增添一点点成熟的魅力,(扯淡)
帮忙看看

_______________________________________________________________________
当我单击更新或删除时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编辑过]

10 回复
#2
Kendy1234562007-03-28 16:26
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)

去掉红色的那个逗号
#3
mldark2007-03-28 16:26
晕了  ...........
#4
tm_ma2007-03-28 16:42
还是不行啊:
IE说:至少一个参数没有被指定值。
#5
tm_ma2007-03-28 16:45
我的关键字段是sitename,字符串类型,我不知道这样写对不对:mydatagrid.datakeys(e.item.itemindex)
#6
bygg2007-03-28 16:49
sitename 这是个什么类型啊?

怎么你的html代码中没有head部啊??
#7
tm_ma2007-03-28 16:52

文本类型,head部分不是可有可无吗

#8
bygg2007-03-28 16:56
sql="update wwwlink set sitename='" & texsitename.text & "',url='" & texurl.text & "',intro='" & texintro.text & "',grade='" & texgrade.text & "' where sitename='" & mydatagrid.datakeys(e.item.itemindex) & "'"
#9
tm_ma2007-03-28 17:05
give me five!oh...yeah!got it  you so cool
#10
Kendy1234562007-03-28 17:46
give me ten! oh...yeah! see it, you so fool~   (Just a joke only)
#11
tuablove2007-03-28 18:56

vb.net 的 看不懂

1