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

📄 form1.frm

📁 VB连接SQL实例,对初学者很有帮助,帮助大大滴有
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "删除记录"
   ClientHeight    =   3090
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   5460
   LinkTopic       =   "Form1"
   ScaleHeight     =   3090
   ScaleWidth      =   5460
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton Command1 
      Caption         =   "删除记录"
      Height          =   615
      Left            =   1560
      TabIndex        =   0
      Top             =   960
      Width           =   2415
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public Sub DeleteX()
   '定义有关的ADO对象和使用的变量。
   Dim rstRoySched As ADODB.Recordset
   Dim strCnn As String
   Dim strMsg As String
   Dim strTitleID As String
   Dim intLoRange As Integer
   Dim intHiRange As Integer
   Dim intRoyalty As Integer
   '打开 RoySched 表。
   strCnn = "Provider=sqloledb;Data Source=mynetserver;Initial Catalog=pubs;User Id=sa;Password=12345678; "
   '定义和生成记录集。
   Set rstRoySched = New ADODB.Recordset
   rstRoySched.CursorLocation = adUseClient
   rstRoySched.CursorType = adOpenStatic
   rstRoySched.LockType = adLockBatchOptimistic
   rstRoySched.Open "SELECT * FROM roysched " & _
      "WHERE royalty = 20", strCnn, , , adCmdText
   ' 提示删除记录。
   strMsg = "符合条件的记录共有:" & _
      rstRoySched.RecordCount & vbCr & vbCr
   '显示符合条件的记录。
   Do While Not rstRoySched.EOF
      strMsg = strMsg & rstRoySched!title_id & vbCr
      rstRoySched.MoveNext
   Loop
   '选择要删除的记录的ID
strMsg = strMsg & vbCr & vbCr & _
      "输入要删除的记录的ID:"
   strTitleID = UCase(InputBox(strMsg))
   '将要删除的记录的字段值保存到临时变量中以便恢复
   rstRoySched.Filter = "title_id = '" & strTitleID & "'"
   intLoRange = rstRoySched!lorange
   intHiRange = rstRoySched!hirange
   intRoyalty = rstRoySched!royalty
   '调用Delete和UpdateBatch方法删除记录
   rstRoySched.Delete
   rstRoySched.UpdateBatch
   '显示结果
   rstRoySched.Filter = adFilterNone
   rstRoySched.Requery
   strMsg = ""
   strMsg = "删除后的记录数:" & _
      rstRoySched.RecordCount & vbCr & vbCr
   Do While Not rstRoySched.EOF
      strMsg = strMsg & rstRoySched!title_id & vbCr
      rstRoySched.MoveNext
   Loop
   MsgBox strMsg
   '恢复数据,因为这只是演示
   rstRoySched.AddNew
   rstRoySched!title_id = strTitleID
   rstRoySched!lorange = intLoRange
   rstRoySched!hirange = intHiRange
   rstRoySched!royalty = intRoyalty
   rstRoySched.UpdateBatch
   rstRoySched.Close
End Sub


Private Sub Command1_Click()
 Call DeleteX
End Sub

⌨️ 快捷键说明

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