USING OLEDB Command

xiaoxiao2021-03-06  20

'

****************************************

'

USING OLEDB Command

'

By: WGSCD

'

QQ153964481

'

***************************************

'

First create a database that is called "WGSCD" with Accass

'

Field: Number, Phone, Address, QQ, Mail

'

Saving path: c: /me/source_file/wgscd.mdb

'

***************************************

Public

Class Form1

Class Form1 Inherits System.Windows.Forms.Form # Region "Windows Form Designer Generated Code" Public Sub New () Sub New () MyBase.new () 'This call is required for the Windows Form Designer. InitializationComponent () 'Add any initialized End Sub' form to clean up the component list after the initializeComponent () call. Protected Overloads Overrides Sub Dispose () Sub Dispose (ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose () End If End If MyBase.Dispose (disposing) End Sub 'Windows Form Designer Required Private Components as System.comPonentModel.icontainer 'Note: The following procedure is necessary to use the Windows Form Designer to modify this process using the Windows Form Designer. 'Don't modify it using the code editor.

Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid Friend WithEvents Button2 As System.Windows.Forms.Button Friend WithEvents Button3 As System.Windows.Forms.Button Friend WithEvents DataGridTableStyle1 As System. Windows.Forms.DataGridTableStyle Friend WithEvents TextBox1 As System.Windows.Forms.TextBox Private Sub InitializeComponent () Sub InitializeComponent () Me.Button1 = New System.Windows.Forms.Button Me.DataGrid1 = new System.Windows.Forms.DataGrid Me.DataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle Me.Button2 = new System.Windows.Forms.Button Me.Button3 = new System.Windows.Forms.Button Me.TextBox1 = new System .Windows.Forms.TextBox ctype (me.datagrid1, system.componentmodel.isupportinitialize) .begininit () me.suspendlayout () '' Button1 'me.button1.locatio n = new system.drawing.point (528, 24) me.button1.name = "Button1" me.button1.size = new system.drawing.size (88, 32) me.button1.tabindex = 1 me.button1. Text = "Delete" '' DataGrid1 'Me.DataGrid1.BackgroundColor = System.Drawing.Color.Tan Me.DataGrid1.CaptionText = "oleDb demo By wgscd" Me.DataGrid1.DataMember = "" Me.DataGrid1.HeaderForeColor = System. Drawing.systemcolors.ControlText Me.DataGrid1.Location = New System.drawing.point (24, 72) Me.DataGrid1.name = "DataGrid1" me.DataGrid1.size =

New System.Drawing.Size (608, 304) Me.DataGrid1.TabIndex = 2 Me.DataGrid1.TableStyles.AddRange (New System.Windows.Forms.DataGridTableStyle () {Me.DataGridTableStyle1}) '' DataGridTableStyle1 'Me.DataGridTableStyle1. BackColor = System.Drawing.Color.Blue Me.DataGridTableStyle1.DataGrid = Me.DataGrid1 Me.DataGridTableStyle1.HeaderBackColor = System.Drawing.Color.FromArgb (CType (128, Byte), CType (255, Byte), CType (255, byte)) Me.DataGridTableStyle1.HeaderFont = New System.Drawing.Font ( "Arial", 12.0 !, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType (134, byte)) Me.DataGridTableStyle1. HeaderForeColor = System.Drawing.SystemColors.ControlText Me.DataGridTableStyle1.LinkColor = System.Drawing.Color.RosyBrown Me.DataGridTableStyle1.MappingName = "" Me.DataGridTableStyle1.SelectionBackColor = System.Drawing.Color.FromArgb (CType (255, Byte) , Ctype (192, byte), ctype (255, byte) ' 'Button2' me.button2.location = new system.drawing.point (40, 16) me.button2.name = "Button2" me.button2.size = new system.drawing.size (88, 32) me.button2. TabINDEX = 3 me.button2.text = "add new row" 'Button3' me.button3.location = new system.drawing.point (160, 16) me.button3.name = "Button3" me.button3.size = New system.drawing.size (152, 32) me.button3.tabindex = 4 me.button3.text = "insert command" '' TextBox1 'me.textbox1.location =

New system.drawing.point (440, 32) me.textbox1.name = "textbox1" me.textbox1.size = new system.drawing.size (72, 21) me.textbox1.tabindex = 5 me.TextBox1.text = "TextBox1" 'FORM1' me.doscalebasesize = new system.drawing.size (6, 14) me.back.fromargb (ctype (255, byte), ctype (224, byte), CType 192, byte)) Me.ClientSize = new system.drawing.size (696, 430) me.controls.add (me.textbox1) Me.Controls.add (me.button3) me.controls.add (me.button2) Me.Controls.add (me.datagrid1) me.controls.add (me.button1) me.name = "form1" me.text = "form1" ctype (me.dataGrid1, system.componentmodel.isupportinitialize) .endinit () Me.ResumeLayout (false) End Sub # End Region Dim strconn as string = "provider = microsoft.jet.Oledb.4.0; data source = c: /me/source_file/wgscd.mdb" DIM DS AS NEW DATASET ("DS" ) DIM DT AS New DataTable ("TB") DIM OLECONN AS NEW OleDbConnection (strconn) Dim olecmd As New OleDbCommand ( "select * from beauty contact details", oleconn) 'Women List ")' Private Sub Button1_Click () Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try If oleconn.State = ConnectionState.Open Then If CInt (TextBox1.Text)> 0 Then olecmd.CommandText = "delete from beauty contact where id =" & TextBox1.Text olecmd.ExecuteNonQuery () oleconn.Close ( ) Msgbox ("ID" & textBox1.text & "

Record successfully deleted! ") 'Me.DataGrid1 = Nothing' Me.DataGrid1.Refresh () End If Else End If getDb () Catch ex As Exception MsgBox (ex.Message) End Try End Sub Private Sub Form1_Load () Sub Form1_Load (ByVal sender As System . Object, Byval e as system.eventargs Handles mybase.load getdb () End Sub Dim Olead As New OLEDBDATAADAPTER (OLECMD) SUB GETDB () SUB GETDB () TRY OLECONN.Open () Olead.Fill (DS) DT = DS .Tables (0) DataGrid1.DataSource = dt TextBox1.Text = dt.Rows.Count Catch ex As Exception MsgBox (ex.Message) End Try End Sub Private Sub Button2_Click () Sub Button2_Click (ByVal sender As System.Object, ByVal e As system.Eventargs Handles Button2.Click DIM DR AS DATAROW = DT.NEWROW DR (0) = "999" DR (1) = "77" DR (2) = "0407" DR (3) = "767" DR (4) = "737" DR (5) = "737" DT.ROWS.ADD (DR) DT.Acceptchange () ds.acceptchanges () end sub private sub button3_click () Sub Button3_Click (BYVAL Sender As System.Object, ByVal E AS System.EventArgs) Handles button3.click trynessState.Open1 'Add record command string OLECMD.COMMANDTEXT = "INSERT INTO beauty contact information (number, phone, address, qq, mail) VALUES (@ TID, @ phone, @ addr , @ qq, @ Mail "Olecmd.Parameters.Add (" @ TID "," 66 ") Olecmd.Parameters.Add (" @ phone "," 665454 "

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

New Post(0)