用ado+来删除数据

caojschy

caojschy

2016-01-29 13:51

用ado+来删除数据,用ado+来删除数据
<%@ Import Namespace="System.Data" %
<%@ Import Namespace="System.Data.SQL" %

<html

<script language="VB" runat="server"

Dim MyConnection As SQLConnection

Sub Page_Load(Src As Object, E As EventArgs)

MyConnection = New SQLConnection("server=YOUR-SERVER;uid=joeuser;pwd=joeuser;database=pubs")

If Not (IsPostBack)
BindGrid()
End If
End Sub

Sub MyDataGrid_Delete(Sender As Object, E As DataGridCommandEventArgs)

Dim MyCommand As SQLCommand
Dim DeleteCmd As String = "DELETE from Authors where au_id = @Id"

MyCommand = New SQLCommand(DeleteCmd, MyConnection)
MyCommand.Parameters.Add(New SQLParameter("@Id", SQLDataType.VarChar, 11))
MyCommand.Parameters("@Id").Value = MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))

MyCommand.ActiveConnection.Open()

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com)

Try
MyCommand.ExecuteNonQuery()
Message.InnerHtml = "<bRecord Deleted</b<br" & DeleteCmd
Catch Exp As SQLException
Message.InnerHtml = "ERROR: Could not delete record"
Message.Style("color") = "red"
End Try

MyCommand.ActiveConnection.Close()

BindGrid()
End Sub

Sub BindGrid()

Dim DS As DataSet
Dim MyCommand As SQLDataSetCommand
MyCommand = New SQLDataSetCommand("select * from Authors", MyConnection)

DS = new DataSet()
MyCommand.FillDataSet(DS, "Authors")

MyDataGrid.DataSource=DS.Tables("Authors").DefaultView
MyDataGrid.DataBind()
End Sub

</script

<body style="font: 10pt verdana"

<form runat="server"

<h3<font face="Verdana"Deleting a Row of Data</font</h3

<span id="Message" MaintainState="false" style="font: arial 11pt;" runat="server"/<p

<ASP:DataGrid id="MyDataGrid" runat="server"
Width="800"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
DataKeyField="au_id"
OnDeleteCommand="MyDataGrid_Delete"

<property name="Columns"
<asp:ButtonColumn Text="Delete Author" CommandName="Delete"/
</property

</ASP:DataGrid

</form

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com)

</body
</html

展开更多 50%)
分享

猜你喜欢

用ado+来删除数据

电脑网络
用ado+来删除数据

用SQL删除数据

编程语言 网络编程
用SQL删除数据

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

妙用SQL子查询来从子表里删除数据

SQLServer
妙用SQL子查询来从子表里删除数据

修改、删除数据记录(DELETEUPDATE)

编程语言 网络编程
修改、删除数据记录(DELETEUPDATE)

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

(DELETEUPDATE)修改、删除数据记录

编程语言 网络编程
(DELETEUPDATE)修改、删除数据记录

ADO+管理器功能

ASP
ADO+管理器功能

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

开发者面临的.Net挑战(一)

开发者面临的.Net挑战(一)

MySQL 4.1的编码问题

MySQL 4.1的编码问题
下拉加载更多内容 ↓