dataset删除数据
2004-09-14 16:39
246 查看
Imports System.Data
Imports System.Data.OleDb
Public Class WebForm4
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
mydatashow()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Write(DropDownList1.SelectedItem.Value)
Dim myconnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("aspnet.mdb"))
Dim myadapter As OleDbDataAdapter = New OleDbDataAdapter("select * from student where id=" + DropDownList1.SelectedItem.Value.ToString, myconnection)
Dim mydataset As DataSet = New DataSet
myadapter.Fill(mydataset, "student")
Dim mybuilder As OleDbCommandBuilder = New OleDbCommandBuilder(myadapter)
mydataset.Tables("student").Rows(0).Delete()
myadapter.Update(mydataset, "student")
mydatashow()
End Sub
Private Function mydatashow()
Dim myconnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("aspnet.mdb"))
Dim myadapter As OleDbDataAdapter = New OleDbDataAdapter("select * from student ", myconnection)
Dim mydataset As DataSet = New DataSet
myadapter.Fill(mydataset, "student")
DataGrid1.DataSource = mydataset.Tables("student").DefaultView
DataGrid1.DataBind()
DropDownList1.DataSource = mydataset.Tables("student").DefaultView
DropDownList1.DataTextField = "id"
DropDownList1.DataValueField = "id"
DropDownList1.DataBind()
myconnection.Close()
End Function
End Class
Imports System.Data.OleDb
Public Class WebForm4
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
mydatashow()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Write(DropDownList1.SelectedItem.Value)
Dim myconnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("aspnet.mdb"))
Dim myadapter As OleDbDataAdapter = New OleDbDataAdapter("select * from student where id=" + DropDownList1.SelectedItem.Value.ToString, myconnection)
Dim mydataset As DataSet = New DataSet
myadapter.Fill(mydataset, "student")
Dim mybuilder As OleDbCommandBuilder = New OleDbCommandBuilder(myadapter)
mydataset.Tables("student").Rows(0).Delete()
myadapter.Update(mydataset, "student")
mydatashow()
End Sub
Private Function mydatashow()
Dim myconnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("aspnet.mdb"))
Dim myadapter As OleDbDataAdapter = New OleDbDataAdapter("select * from student ", myconnection)
Dim mydataset As DataSet = New DataSet
myadapter.Fill(mydataset, "student")
DataGrid1.DataSource = mydataset.Tables("student").DefaultView
DataGrid1.DataBind()
DropDownList1.DataSource = mydataset.Tables("student").DefaultView
DropDownList1.DataTextField = "id"
DropDownList1.DataValueField = "id"
DropDownList1.DataBind()
myconnection.Close()
End Function
End Class
相关文章推荐
- winForm中DataSet实现数据查询、保存和删除
- dataset中删除重复数据
- CheckBox与DataGrid混用&DataSet批量删除数据
- winForm中DataSet实现数据查询、保存和删除
- winForm中DataSet实现数据查询、保存和删除 .
- dataset中删除重复数据
- 【转】dataset中删除重复数据
- 通过Dataset操作xml数据(添加,删除,修改)
- C# 在dataset内删除数据
- 通过CommandBuilder对DataSet数据进行添加、修改、删除
- 删除DATASET中行数据技巧
- dataset中删除重复数据
- 使用CommandBuilder对象时,DataSet中的数据删除
- 删除DATASET中行数据技巧
- CheckBox与DataGrid混用&DataSet批量删除数据
- DataSet 删除数据
- winForm中DataSet实现数据查询、保存和删除
- DataSet SqlCommandBuilder添加修改删除数据
- DataSet增加修改删除一个数据
- mysql-删除重复数据