dataset删改数据

Imports System.Data
Imports System.Data.OleDb

Public Class WebForm5
    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 DropDownList1 As System.Web.UI.WebControls.DropDownList
    Protected WithEvents DropDownList2 As System.Web.UI.WebControls.DropDownList
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents Button2 As System.Web.UI.WebControls.Button
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Button3 As System.Web.UI.WebControls.Button
    Protected WithEvents xuhu As System.Web.UI.HtmlControls.HtmlGenericControl
    Protected WithEvents Button4 As System.Web.UI.WebControls.Button

    '注意: 以下占位符声明是 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
            xuhu.Visible = False
            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")
        myconnection.Close()
        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()
        DropDownList2.DataSource = mydataset.Tables("student").Columns
        DropDownList2.DataBind()
        myconnection.Close()
    End Function

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        xuhu.Visible = True
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        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)(DropDownList2.SelectedItem.Value) = TextBox1.Text
        myadapter.Update(mydataset, "student")
        myconnection.Close()
        mydatashow()
        xuhu.Visible = False
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        xuhu.Visible = False
    End Sub
End Class

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值