精品推荐
阅读排行
· 查看svchost.exe进程· PRO/E 十种技巧
· [组图] 3ds Max 高级长篇人
· [组图] PRO/E的曲面设计
· 怎样学好PRO/E软件?
· 路由技术介绍
· Pro/ENGINEER 学习资
· xml的应用是什么?x
· [组图] Photoshop制作珠宝文
· [组图] flash人物绘画教程
| 作者:不明 来源:www.pccode.net 整理 发布时间:2006-5-17 12:50:44 发布人:wongrs |
| <%@ 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() Try MyCommand.ExecuteNonQuery() Message.InnerHtml = "<b>Record Deleted</b>" & 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> </body> </html> < |
| [ ] [返回上一页] [打 印] [收 藏] |
上一篇文章:模拟SQL Server的两个日期处理函数
下一篇文章:SQL Server存储过程编程经验技巧 |
