| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 690 人关注过本帖
标题:[求助]delete不到database records(参考www.asp101.com的sample做的)
只看楼主 加入收藏
wcchyau
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-3-22
收藏
 问题点数:0 回复次数:3 
[求助]delete不到database records(参考www.asp101.com的sample做的)

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<HTML>
<script language="VB" runat="server">

Sub Page_Load(Sender As Object, E As EventArgs)
Dim objConn As New oleDbConnection
objConn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;"
objConn.ConnectionString+= "Data Source= " & Server.MapPath("Account.mdb")
ShowDataGrid()
End Sub

Sub ShowDataGrid()
Dim objCommand As oleDbCommand
Dim strSQLQuery As String
Dim objConn As New oleDbConnection
objConn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;"
objConn.ConnectionString+= "Data Source= " & Server.MapPath("Account.mdb")

strSQLQuery = "SELECT * FROM ordered;"

objCommand = New OleDbCommand(strSQLQuery, objConn)
objConn.Open()

OP.DataSource = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
OP.DataBind()

objConn.Close()
End Sub

Sub Delete(source As Object, E As DataGridCommandEventArgs)
Dim objCommand As oleDbCommand
Dim strSQLQuery As String
Dim objConn As New oleDbConnection
objConn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;"
objConn.ConnectionString+= "Data Source= " & Server.MapPath("Account.mdb")

strSQLQuery = "DELETE FROM ordered WHERE No=" & OP.DataKeys(E.Item.ItemIndex) & ";"

objCommand = New OleDbCommand(strSQLQuery, objConn)
objConn.Open()
objCommand.ExecuteNonQuery()
objConn.Close()
ShowDataGrid()

End Sub


</script>
<body>
<form runat="server" ID="Form1">
<asp:DataGrid id="OP" runat="server" DataKeyField="No">
<Columns>
<asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:DataGrid>
</form>
<p>
</p>
</body>
</HTML>
搜索更多相关主题的帖子: database delete sample records 
2007-05-07 00:26
wcchyau
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-3-22
收藏
得分:0 
database是显示出来了,但按delete时却不能像sample般把record delete掉
strSQLQuery = "DELETE FROM ordered WHERE No=" & OP.DataKeys(E.Item.ItemIndex) & ";"
感觉上是这行code的问题,但却不知为什么。
能否给些指教呢?谢谢
2007-05-07 00:27
川流不息
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:2000
专家分:47
注 册:2006-11-8
收藏
得分:0 
strSQLQuery = "DELETE FROM ordered WHERE No=" & OP.DataKeys(E.Item.ItemIndex) & ";"


你把它輸出來後在查詢分析器裡面運行,看能不能夠成功。如果不能成功的話就是語句的問題,如果成功就是程式的問題,那就要再研究。

日月更替,天地輪回,人間已是幾回春。 江山不老,人正少年,只手能擎半邊天。
2007-05-07 08:47
tel1982
Rank: 3Rank: 3
来 自:水星
等 级:新手上路
威 望:8
帖 子:852
专家分:0
注 册:2006-10-21
收藏
得分:0 

我觉得好像你的程式语句有错误。
Sub Delete(source As Object, E As DataGridCommandEventArgs)
Dim objCommand As oleDbCommand
Dim strSQLQuery As String
Dim objConn As New oleDbConnection
objConn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;"
objConn.ConnectionString+= "Data Source= " & Server.MapPath("Account.mdb")
objConn.Open()
strSQLQuery = "DELETE FROM ordered WHERE No=" & OP.DataKeys(E.Item.ItemIndex) & ";" objCommand = New OleDbCommand(strSQLQuery, objConn)

objCommand.ExecuteNonQuery()
objConn.Close()
ShowDataGrid()
End Sub
是不是应该这样呀?
你试一试。


Face up to life with smiles no matter what happens
2007-05-07 09:45
快速回复:[求助]delete不到database records(参考www.asp101.com的sample做的)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025501 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved