📄 frmtest.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmTest
Caption = "存储数据库"
ClientHeight = 4260
ClientLeft = 60
ClientTop = 345
ClientWidth = 7170
LinkTopic = "Form1"
LockControls = -1 'True
ScaleHeight = 4260
ScaleWidth = 7170
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdRead
Caption = "读取数据库"
Height = 465
Left = 5310
TabIndex = 6
Top = 1260
Width = 1725
End
Begin VB.TextBox txtCode
Height = 330
Left = 5580
TabIndex = 5
Top = 855
Width = 1050
End
Begin MSComDlg.CommonDialog dlgOpen
Left = 5535
Top = 1125
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.CommandButton cmdIn
Caption = "写入数据库"
Height = 465
Left = 5310
TabIndex = 4
Top = 135
Width = 1725
End
Begin VB.PictureBox picSur
Height = 3705
Left = 90
ScaleHeight = 3645
ScaleWidth = 4950
TabIndex = 3
Top = 450
Width = 5010
End
Begin VB.CommandButton cmdPath
Caption = "..."
Height = 330
Left = 4590
TabIndex = 2
Top = 45
Width = 510
End
Begin VB.TextBox txtPath
Height = 285
Left = 810
TabIndex = 1
Top = 90
Width = 3705
End
Begin VB.Label Label1
Caption = "文件:"
Height = 195
Left = 135
TabIndex = 0
Top = 135
Width = 600
End
End
Attribute VB_Name = "frmTest"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Conn As New ADODB.Connection
Private Sub cmdIn_Click()
Dim L As Long
Dim BLob() As Byte
Dim F As Long
Dim Rec As New ADODB.Recordset
L = FileLen(txtPath)
ReDim BLob(L)
'打开文件
Open txtPath For Binary As #1
Get #1, , BLob
Close #1
Rec.Open "Select * from P", Conn, adOpenKeyset, adLockOptimistic, adCmdText
Rec.AddNew
Rec("Code") = "001"
Rec("P") = BLob
Rec.Update
MsgBox "装入完成!"
Set Rec = Nothing
End Sub
Private Sub cmdPath_Click()
dlgOpen.DialogTitle = "选择文件..."
dlgOpen.Filter = "图象文件|*.jpg"
dlgOpen.ShowOpen
txtPath = dlgOpen.FileName
picSur.Picture = LoadPicture(txtPath)
End Sub
Private Sub cmdRead_Click()
Dim BLob() As Byte
Dim L As Long
Dim Fso As New FileSystemObject
Dim Rec As New ADODB.Recordset
Rec.Open "Select * from P Where Code='" + Trim(txtCode) + "'", Conn
L = Rec("P").ActualSize
ReDim BLob(L)
BLob = Rec("P")
If Fso.FileExists(App.Path + "\Temp.jpg") Then
Fso.DeleteFile App.Path + "\Temp.jpg"
End If
Open App.Path + "\Temp.jpg" For Binary As #1
Put #1, , BLob
Close #1
picSur.Picture = LoadPicture(App.Path + "\Temp.jpg")
Set Rec = Nothing
End Sub
Private Sub Form_Load()
Conn.ConnectionString = "driver={SQL Server};Server=.;Uid=sa;Pwd=;"
Conn.ConnectionTimeout = 15
Conn.CursorLocation = adUseClient
Conn.Open
Conn.DefaultDatabase = "Pubs"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -