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

📄 form1.frm

📁 利用ado控件访问SQL数据库
💻 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"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomct2.ocx"
Object = "{0002E558-0000-0000-C000-000000000046}#1.0#0"; "OWC11.DLL"
Begin VB.Form Form1 
   BackColor       =   &H80000009&
   Caption         =   "运行日志"
   ClientHeight    =   8880
   ClientLeft      =   8055
   ClientTop       =   1455
   ClientWidth     =   9885
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   935.229
   ScaleLeft       =   800
   ScaleMode       =   0  'User
   ScaleWidth      =   9885
   Begin VB.CommandButton Command1 
      Caption         =   "打印"
      Height          =   540
      Left            =   6720
      TabIndex        =   3
      Top             =   7665
      Width           =   1170
   End
   Begin OWC11.Spreadsheet Spreadsheet1 
      Height          =   5055
      Left            =   105
      OleObjectBlob   =   "Form1.frx":0000
      TabIndex        =   2
      Top             =   210
      Width           =   9570
   End
   Begin VB.TextBox Text1 
      Height          =   330
      Left            =   3150
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   7980
      Width           =   2640
   End
   Begin MSComCtl2.DTPicker DTPicker1 
      Height          =   435
      Left            =   1155
      TabIndex        =   0
      Top             =   7875
      Width           =   1695
      _ExtentX        =   2990
      _ExtentY        =   767
      _Version        =   393216
      Format          =   25493505
      UpDown          =   -1  'True
      CurrentDate     =   39355
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Align           =   2  'Align Bottom
      Height          =   495
      Left            =   0
      Top             =   8385
      Width           =   9885
      _ExtentX        =   17436
      _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  =   "liu"
      OtherAttributes =   ""
      UserName        =   "sa"
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "Adodc1"
      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 MSDataGridLib.DataGrid DataGrid1 
      Bindings        =   "Form1.frx":0B1A
      Height          =   1710
      Left            =   0
      TabIndex        =   4
      Top             =   5460
      Width           =   9885
      _ExtentX        =   17436
      _ExtentY        =   3016
      _Version        =   393216
      ColumnHeaders   =   -1  'True
      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 
            ColumnWidth     =   -4.5516e5
         EndProperty
         BeginProperty Column01 
            ColumnWidth     =   -4.5516e5
         EndProperty
      EndProperty
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command1_Click()
On Error Resume Next
Dim T_excel As Object
Dim Print_excel As Object
Set T_excel = Spreadsheet1.Constants
Set Print_excel = CreateObject("excel.Application")

Spreadsheet1.Export "E:/liu11.xls", T_excel.ssExportActionNone
Print_excel.Workbooks.Open "E:/liu11.xls"
Print_excel.Application.Visible = True
Print_excel.ActiveWorkbook.PrintOut
Print_excel.Application.Quit
Set Print_excel = Nothing
Set T_excel = Nothing
End Sub

Private Sub DTPicker1_Change()
Dim xx
xx = 1
   Do While Spreadsheet1.Cells(xx, 1).Value <> ""
        xx = xx + 1
   Loop
Dim ii As Integer
   Dim jj
   For jj = 0 To xx - 1
   For ii = 0 To 4
     If Not Adodc1.Recordset.BOF Or Not Adodc1.Recordset.EOF Then
        Spreadsheet1.Cells(jj + 1, 1).NumberFormat = "HH:MM:SS"
        Spreadsheet1.Cells(jj + 1, ii + 1).Value = Null
     End If
   Next ii
   Next jj
Dim min As String
Dim max$
'DTPicker1.Value = DateAdd("d", -1, Date)
min = DTPicker1.Value & " 00:00:00"
max = DTPicker1.Value & " 23:59:59"
With Adodc1
   .ConnectionString = "driver={SQL Server};" & "server=(local);uid=sa;pwd=;database=liu11"
   .RecordSource = "Select * From kkkkkk where timestamp between '" + min + "' and '" + max + "'"
End With
   Set DataGrid1.DataSource = Adodc1
   Adodc1.Refresh

   If Not Adodc1.Recordset.BOF Or Not Adodc1.Recordset.EOF Then
      Adodc1.Recordset.MoveFirst
   End If
'Set Print_excel = CreateObject("excel.sheet")
   Dim i As Integer
   Dim j As Integer
   For j = 0 To Adodc1.Recordset.RecordCount - 1
   For i = 0 To 4
     If Not Adodc1.Recordset.BOF Or Not Adodc1.Recordset.EOF Then
        Spreadsheet1.Cells(j + 1, 1).NumberFormat = "HH:MM:SS"
        Spreadsheet1.Cells(j + 1, i + 1).Value = Adodc1.Recordset(i)
     End If
    
   Next i
   If Not Adodc1.Recordset.BOF Or Not Adodc1.Recordset.EOF Then
       Adodc1.Recordset.MoveNext
   End If
   Next j
   

   Text1.Text = xx - 1
  ' MsgBox "kkk"
End Sub

Private Sub Form_Load()
Dim min As String
Dim max$
DTPicker1.Value = DateAdd("d", -1, Date)
min = DTPicker1.Value & " 00:00:00"
max = DTPicker1.Value & " 23:59:59"
With Adodc1
   .ConnectionString = "driver={SQL Server};" & "server=(local);uid=sa;pwd=;database=liu11"
   .RecordSource = "Select * From kkkkkk where timestamp between '" + min + "' and '" + max + "'"
  End With
   Set DataGrid1.DataSource = Adodc1
Text1.Text = min
   If Not Adodc1.Recordset.BOF Or Not Adodc1.Recordset.EOF Then
      Adodc1.Recordset.MoveFirst
   End If
'Set Print_excel = CreateObject("excel.sheet")
   Dim i As Integer
   Dim j As Integer
   For j = 0 To Adodc1.Recordset.RecordCount - 1
   For i = 0 To 4
     If Not Adodc1.Recordset.BOF Or Not Adodc1.Recordset.EOF Then
        Spreadsheet1.Cells(j + 1, 1).NumberFormat = "HH:MM:SS"
        Spreadsheet1.Cells(j + 1, i + 1).Value = Adodc1.Recordset(i)
     End If
   Next i
   If Not Adodc1.Recordset.BOF Or Not Adodc1.Recordset.EOF Then
       Adodc1.Recordset.MoveNext
   End If
   Next j

End Sub
   
   
   
   
   
   
  

⌨️ 快捷键说明

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