DataSet Delete Data

xiaoxiao2021-03-06  50

Imports System.DataImports System.Data.Oledb

Public class Webform5 inherits system.web.ui.page

#Region "The code" of the web form designer "

'This call is required for the web form designer. private subinitializecomponent ()

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

'Note: The following placeholders declare are required by the web form designer. 'Don't delete or move it. Private DesignerPlaceHolderDeclaration as System.Object

Private Sub Page_init (Byval E AS System.EventArgs) Handles mybase.init 'Codegen: This method call is required by the Web Form Designer' Do not modify it using the code editor. InitializationComponent () End Sub

#End region

Private sub page_load (Byval e as system.EventArgs) Handles mybase.load if not ispostback kilnuhu.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 OL eDbDataAdapter = 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 FunctionPrivate 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 E AS System.EventArgs) Handles Button4.Click Xuhu.visible = False End Subend Class

转载请注明原文地址:https://www.9cbs.com/read-116883.html

New Post(0)