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

📄 main.frm

📁 数据库读写实例
💻 FRM
📖 第 1 页 / 共 3 页
字号:
      EndProperty
      Height          =   645
      Index           =   4
      Left            =   5820
      TabIndex        =   13
      Top             =   1590
      Width           =   1770
   End
   Begin VB.Label Label3 
      BorderStyle     =   1  'Fixed Single
      Caption         =   " ADRESS"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9
         Charset         =   162
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   975
      Index           =   0
      Left            =   5820
      TabIndex        =   12
      Top             =   615
      Width           =   1770
   End
   Begin VB.Label Label2 
      BorderStyle     =   1  'Fixed Single
      Caption         =   " FAX"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9
         Charset         =   162
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Index           =   0
      Left            =   0
      TabIndex        =   11
      Top             =   1920
      Width           =   1770
   End
   Begin VB.Label Label1 
      BorderStyle     =   1  'Fixed Single
      Caption         =   " TELEPHONE 2"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9
         Charset         =   162
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Index           =   0
      Left            =   0
      TabIndex        =   10
      Top             =   1590
      Width           =   1770
   End
   Begin VB.Label Label6 
      BorderStyle     =   1  'Fixed Single
      Caption         =   " NAME"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9
         Charset         =   162
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Index           =   2
      Left            =   0
      TabIndex        =   9
      Top             =   630
      Width           =   1770
   End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim SorSor As Boolean
Private Sub Form_Load()
    Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\adodb1.mdb;Persist Security Info=False"
    Adodc1.RecordSource = "SELECT * FROM Table1"
    Adodc1.Refresh
    If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast
    Me.Caption = "ADODB SAMPLE[ Record Count : " & Adodc1.Recordset.RecordCount & "]"
    Set DataGrid1.DataSource = Adodc1
    SorSor = False
End Sub
Private Sub Form_Resize()
On Error GoTo aa:
DataGrid1.Left = 0
DataGrid1.Top = 2280
DataGrid1.Width = Me.ScaleWidth
DataGrid1.Height = Me.ScaleHeight - (Text1.Height + Text2.Height + Text3.Height + Text4.Height + Text5.Height + StatusBar2.Height + Toolbar1.Height + 25)
Exit Sub
aa:
Exit Sub
End Sub
Private Sub Text1_Change()
If SorSor = True Then
    Adodc1.RecordSource = "Select * From Table1 Where NAME LIKE '" & Text1 & "%';"
    Adodc1.Refresh
    If Text1 = "" Then
        Text1 = "": Text2 = "": Text3 = ""
        Text4 = "": Text5 = "": Text6 = ""
        Text7 = ""
    End If
End If
End Sub

Private Sub Text2_Change()
If SorSor = True Then
    Adodc1.RecordSource = "Select * From Table1 Where SURNAME LIKE '" & Text2 & "%';"
    Adodc1.Refresh
    If Text2 = "" Then
        Text1 = "": Text2 = "": Text3 = ""
        Text4 = "": Text5 = "": Text6 = ""
        Text7 = ""
    End If
End If

End Sub

Private Sub Text3_Change()
If SorSor = True Then
    Adodc1.RecordSource = "Select * From Table1 Where TEL1 LIKE '" & Text3 & "%';"
    Adodc1.Refresh
    If Text3 = "" Then
        Text1 = "": Text2 = "": Text3 = ""
        Text4 = "": Text5 = "": Text6 = ""
        Text7 = ""
    End If
End If

End Sub

Private Sub Text4_Change()
If SorSor = True Then
    Adodc1.RecordSource = "Select * From Table1 Where TEL2 LIKE '" & Text4 & "%';"
    Adodc1.Refresh
    If Text4 = "" Then
        Text1 = "": Text2 = "": Text3 = ""
        Text4 = "": Text5 = "": Text6 = ""
        Text7 = ""
    End If
End If
End Sub

Private Sub Text5_Change()
If SorSor = True Then
    Adodc1.RecordSource = "Select * From Table1 Where FAX LIKE '" & Text5 & "%';"
    Adodc1.Refresh
    If Text5 = "" Then
        Text1 = "": Text2 = "": Text3 = ""
        Text4 = "": Text5 = "": Text6 = ""
        Text7 = ""
    End If
End If

End Sub

Private Sub Text6_Change()
If SorSor = True Then
    Adodc1.RecordSource = "Select * From Table1 Where ADRESS LIKE '" & Text6 & "%';"
    Adodc1.Refresh
    If Text6 = "" Then
        Text1 = "": Text2 = "": Text3 = ""
        Text4 = "": Text5 = "": Text6 = ""
        Text7 = ""
    End If
End If

End Sub

Private Sub Text7_Change()
If SorSor = True Then
    Adodc1.RecordSource = "Select * From Table1 Where KNOWLEDGE LIKE '" & Text7 & "%';"
    Adodc1.Refresh
    If Text7 = "" Then
        Text1 = "": Text2 = "": Text3 = ""
        Text4 = "": Text5 = "": Text6 = ""
        Text7 = ""
    End If
End If

End Sub

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
    Select Case Button.Key
            Case "yeni"
                If Toolbar1.Buttons.Item(1).Caption = "New" Then
                    Toolbar1.Buttons.Item(4).Enabled = False
                    Text1.Enabled = 1: Text2.Enabled = 1: Text3.Enabled = 1
                    Text4.Enabled = 1: Text5.Enabled = 1: Text6.Enabled = 1
                    Text7.Enabled = 1
                    Adodc1.Recordset.AddNew
                    Toolbar1.Buttons.Item(1).Caption = "Cancel"
                    Text1.SetFocus
                Else
                    Adodc1.Refresh
                    Toolbar1.Buttons.Item(4).Enabled = True
                    Text1.Enabled = 0: Text2.Enabled = 0: Text3.Enabled = 0
                    Text4.Enabled = 0: Text5.Enabled = 0: Text6.Enabled = 0
                    Text7.Enabled = 0
                    Toolbar1.Buttons.Item(1).Caption = "New"
                End If
            Case "ekle"
                If Not Len(Text1.Text) < 1 Then
                    Adodc1.Recordset.Update
                    Text1.Enabled = 0: Text2.Enabled = 0: Text3.Enabled = 0
                    Text4.Enabled = 0: Text5.Enabled = 0: Text6.Enabled = 0
                    Text7.Enabled = 0
                    Toolbar1.Buttons.Item(1).Caption = "New"
                    Toolbar1.Buttons.Item(4).Enabled = True
                    Me.Caption = "ADODB SAMPLE[ Record Count : " & Adodc1.Recordset.RecordCount & "]"
                Else
                    MsgBox "Mising Data Entry", vbApplicationModal + vbOKOnly + vbCritical, "ERROR !"
                    On Local Error Resume Next
                    Text1.SetFocus
                End If
            Case "sil"
                    If Adodc1.Recordset.RecordCount = 0 Then Exit Sub
                    On Local Error Resume Next
                    Adodc1.Recordset.Delete
                    Me.Caption = "ADODB SAMPLE[ Record Count : " & Adodc1.Recordset.RecordCount & "]"
            Case "sorgu"
                If Toolbar1.Buttons.Item(14).Caption = "Search" Then
                    Toolbar1.Buttons.Item(1).Enabled = False
                    Toolbar1.Buttons.Item(2).Enabled = False
                    Toolbar1.Buttons.Item(4).Enabled = False
                    Toolbar1.Buttons.Item(6).Enabled = False
                    Toolbar1.Buttons.Item(8).Enabled = False
                    Toolbar1.Buttons.Item(9).Enabled = False
                    Toolbar1.Buttons.Item(10).Enabled = False
                    Toolbar1.Buttons.Item(11).Enabled = False
                    Toolbar1.Buttons.Item(14).Caption = "Cancel"
                    Text1.Enabled = 1: Text2.Enabled = 1: Text3.Enabled = 1
                    Text4.Enabled = 1: Text5.Enabled = 1: Text6.Enabled = 1
                    Text7.Enabled = 1
                    DataGrid1.AllowAddNew = False
                    Text1.SetFocus
                    Text1.DataField = "": Text1 = ""
                    Text2.DataField = "": Text2 = ""
                    Text3.DataField = "": Text3 = ""
                    Text4.DataField = "": Text4 = ""
                    Text5.DataField = "": Text5 = ""
                    Text6.DataField = "": Text6 = ""
                    Text7.DataField = "": Text7 = ""
                    SorSor = True
                Else
                    SorSor = False
                    Toolbar1.Buttons.Item(1).Enabled = True
                    Toolbar1.Buttons.Item(2).Enabled = True
                    Toolbar1.Buttons.Item(4).Enabled = True
                    Toolbar1.Buttons.Item(6).Enabled = True
                    Toolbar1.Buttons.Item(8).Enabled = True
                    Toolbar1.Buttons.Item(9).Enabled = True
                    Toolbar1.Buttons.Item(10).Enabled = True
                    Toolbar1.Buttons.Item(11).Enabled = True
                    Toolbar1.Buttons.Item(14).Caption = "Search"
                    Text1.Enabled = 0: Text2.Enabled = 0: Text3.Enabled = 0
                    Text4.Enabled = 0: Text5.Enabled = 0: Text6.Enabled = 0
                    Text7.Enabled = 0
                    DataGrid1.AllowAddNew = True
                    Text1.DataField = "NAME"
                    Text2.DataField = "SURNAME"
                    Text3.DataField = "TEL1"
                    Text4.DataField = "TEL2"
                    Text5.DataField = "FAX"
                    Text6.DataField = "ADRESS"
                    Text7.DataField = "KNOWLEDGE"
                    Adodc1.RecordSource = "Select * From Table1"
                    Adodc1.Refresh
                End If
            Case "cik"
                    Unload Me
            Case "ilk"
                    If Adodc1.Recordset.RecordCount = 0 Then Exit Sub
                    If Not Adodc1.Recordset.BOF Then Adodc1.Recordset.MoveFirst
            Case "once"
                    If Adodc1.Recordset.RecordCount = 0 Then Exit Sub
                    If Not Adodc1.Recordset.BOF Then Adodc1.Recordset.MovePrevious
            Case "sonra"
                    If Adodc1.Recordset.RecordCount = 0 Then Exit Sub
                    If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveNext
            Case "son"
                    If Adodc1.Recordset.RecordCount = 0 Then Exit Sub
                    If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast
            Case "yaz"
                   ' CrystalReport1.ReportFileName = App.Path & "\report.rpt"
                   ' CrystalReport1.RetrieveDataFiles
                   ' CrystalReport1.WindowState = crptMaximized
                   ' CrystalReport1.Action = 1
    End Select
End Sub

⌨️ 快捷键说明

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