⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmdelete.frm

📁 通过实现数据绑定的功能
💻 FRM
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form frmDelete 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "产品删除"
   ClientHeight    =   6765
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   9165
   LinkTopic       =   "Form3"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   6765
   ScaleWidth      =   9165
   ShowInTaskbar   =   0   'False
   Begin VB.Frame Frame2 
      Caption         =   "产品查询删除"
      Height          =   1095
      Left            =   240
      TabIndex        =   2
      Top             =   240
      Width           =   8655
      Begin VB.CommandButton cmdClear 
         Caption         =   "清空"
         Height          =   495
         Left            =   5160
         TabIndex        =   8
         Top             =   360
         Width           =   1095
      End
      Begin VB.TextBox txtName 
         Height          =   495
         Left            =   1680
         TabIndex        =   6
         Top             =   360
         Width           =   1695
      End
      Begin VB.CommandButton cmdQuery 
         Caption         =   "查询"
         Default         =   -1  'True
         Height          =   495
         Left            =   4080
         TabIndex        =   5
         Top             =   360
         Width           =   1095
      End
      Begin VB.CommandButton cmdDelete 
         Caption         =   "删除"
         Height          =   495
         Left            =   6240
         TabIndex        =   4
         Top             =   360
         Width           =   1095
      End
      Begin VB.CommandButton cmdClose 
         Caption         =   "关闭"
         Height          =   495
         Left            =   7320
         TabIndex        =   3
         Top             =   360
         Width           =   1095
      End
      Begin VB.Label Label1 
         Caption         =   "名称"
         Height          =   375
         Left            =   360
         TabIndex        =   7
         Top             =   480
         Width           =   1095
      End
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   495
      Left            =   240
      Top             =   1440
      Width           =   8655
      _ExtentX        =   15266
      _ExtentY        =   873
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   ""
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.Frame Frame1 
      Caption         =   "查询结果"
      Height          =   3975
      Left            =   240
      TabIndex        =   0
      Top             =   2040
      Width           =   8655
      Begin MSDataGridLib.DataGrid DataGrid1 
         Bindings        =   "frmDelete.frx":0000
         Height          =   3375
         Left            =   360
         TabIndex        =   1
         Top             =   360
         Width           =   7935
         _ExtentX        =   13996
         _ExtentY        =   5953
         _Version        =   393216
         HeadLines       =   1
         RowHeight       =   15
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "宋体"
            Size            =   9
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "宋体"
            Size            =   9
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   2
         BeginProperty Column00 
            DataField       =   ""
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   2052
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   ""
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   2052
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
            EndProperty
            BeginProperty Column01 
            EndProperty
         EndProperty
      End
   End
End
Attribute VB_Name = "frmDelete"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdClear_Click()
    '清空查询条件
    txtName.Text = ""
    '设置鼠标焦点
    txtName.SetFocus
End Sub

Private Sub cmdQuery_Click()
    Dim strSQL As String
    '查询不能为空,没有意义
    If Trim(txtName.Text) = "" Then
        MsgBox "查询姓名不能为空!", vbOKOnly + vbExclamation, "警告!"
        Text1.SetFocus
        Exit Sub
    End If
    strSQL = "Select * From product Where 名称 like " + _
    "'" + Replace(Trim(txtName.Text), "'", "''", 1) + "%'"
    '设置Adodc1的连接字符串
    Adodc1.ConnectionString = ConnectString
    '设定Adodc1的命令类型
    Adodc1.CommandType = adCmdText
    '设定Adodc1的记录源
    Adodc1.RecordSource = strSQL
    '刷新Adodc1
    Adodc1.Refresh
End Sub

Private Sub cmdDelete_Click()
    '如果有错则转入出错处理部分
     On Error GoTo DeleteErr
     If MsgBox("您确认删除这条记录吗?", vbExclamation + vbOKCancel, "产品删除") = vbCancel Then
       Exit Sub
     End If
       
     With Adodc1.Recordset
           '如果记录数小于等于0,则没有记录可以删除
           If .RecordCount <= 0 Then
               MsgBox "没有记录可以删除!", vbOKOnly + vbExclamation, "警告!"
               Exit Sub
           End If
           '删除当前记录
           .Delete
           '如果删除后记录数小于等于0,则禁止使用Adodc1
           If .RecordCount <= 0 Then
               Adodc1.Enabled = False
               Exit Sub
           End If
           '因为删除了一条记录,记录移动到下一条
           .MoveNext
           '如果下一条是文件末尾,则移动到最后一条
           If .EOF Then .MoveLast
     End With
     
     Exit Sub
DeleteErr:
    '显示出错信息的描述
     MsgBox Err.Description
End Sub

Private Sub cmdClose_Click()
    '释放窗体本身
    Unload Me
End Sub

Private Sub Form_Load()
    '设置Adodc1的连接字符串
    'Adodc1.ConnectionString = ConnectString
    '设置Adodc1的记录源
    'Adodc1.RecordSource = "Select * From product "
    '将Adodc1和DataGrid1绑定,设置DataGrid1的数据源为Adodc1
    'Set DataGrid1.DataSource = Adodc1
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -