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



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

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