📄 form1.frm
字号:
Begin VB.CommandButton cmdSave
Caption = "保存数据库图片到磁盘文件"
Height = 495
Left = 840
TabIndex = 1
Top = 3480
Width = 2415
End
Begin MSComDlg.CommonDialog dlgOpen
Left = 4560
Top = 420
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.Label Label4
Caption = "学号:"
Height = 255
Left = 4320
TabIndex = 15
Top = 1200
Width = 1095
End
Begin VB.Label Label3
Caption = "显示结果:"
Height = 255
Left = -74520
TabIndex = 14
Top = 960
Width = 1215
End
Begin VB.Label Label2
Caption = "查询结果:"
Height = 375
Left = -74640
TabIndex = 11
Top = 1200
Width = 1455
End
Begin VB.Label Label1
Caption = "输入年级:"
Height = 375
Left = -74280
TabIndex = 10
Top = 480
Width = 1095
End
End
Begin MSAdodcLib.Adodc Adodc1
Height = 495
Left = 240
Top = 5280
Width = 3135
_ExtentX = 5530
_ExtentY = 873
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 0
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 2
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = "Provider=SQLOLEDB.1;Password=begin_sa;Persist Security Info=True;User ID=sa;Initial Catalog=Students;Data Source=GXP"
OLEDBString = "Provider=SQLOLEDB.1;Password=begin_sa;Persist Security Info=True;User ID=sa;Initial Catalog=Students;Data Source=GXP"
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = "sa"
Password = "begin_sa"
RecordSource = ""
Caption = "Adodc1"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public strPath As String
Private Sub cmdAdd_Click()
Adodc1.Recordset.AddNew
Adodc1.Recordset("学号") = Trim(txtNumber.Text)
If strPath <> "" Then
'调用过程中定义的方法
Call oldSaveToDB(Adodc1.Recordset("照片"), strPath)
End If
Adodc1.Recordset.Update
End Sub
Private Sub cmdTrans_Click()
Dim comm As ADODB.Command
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cnnRs As ADODB.Connection
Dim strValue As String
Set comm = New ADODB.Command
Set cnn = New ADODB.Connection
Set cnnRs = New ADODB.Connection
'设置连接属性
cnn.ConnectionString = Adodc1.ConnectionString
cnn.CursorLocation = adUseServer
cnn.Open
'设置Command对象
Set comm.ActiveConnection = cnn
comm.CommandText = "select * from uCoursesTeacher"
comm.CommandType = adCmdText
'返回用于操作的记录集
Set rs = comm.Execute
rs.Close
rs.LockType = adLockOptimistic
rs.Open
'开始一个事务
cnn.BeginTrans
'rs.MoveFirst
Dim i As Integer
For i = 1 To 5
rs.AddNew
rs(0) = i & "_YOU"
rs(1) = i & "_I"
rs(2) = i & "_He"
rs.Update
Next i
'在此处决定事务是否提交或取消,然后来决定对记录集是否更新
If vbYes = MsgBox("完成添加数据吗?", vbYesNo + vbQuestion) Then
'执行该方法,保存数据库中所有的改变
cnn.CommitTrans
Else
'执行该方法,取消数据库中所有的改变
cnn.RollbackTrans
End If
'获取用来显示在DataGrid控件中的记录集
cnnRs.ConnectionString = Adodc1.ConnectionString
cnnRs.CursorLocation = adUseClient
cnnRs.Open
Set comm.ActiveConnection = cnnRs
Set rs = comm.Execute
'在记录集中显示事务处理后的结果
Set DataGrid2.DataSource = rs
End Sub
Private Sub cmdSave_Click()
Dim strAddSql As String
With dlgOpen
.Filter = "all|*.*|bmp|*.bmp"
.ShowSave
strPath = .FileName
End With
'调用标准模块中定义的过程
Call oldGetFromDB(Adodc1.Recordset("照片"), strPath)
'在PicturBox框中显示保存到磁盘上的文件
picPhoto.Picture = LoadPicture(strPath)
End Sub
Private Sub cmdQuery_Click()
Dim comm As ADODB.Command
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim Param As ADODB.Parameter
Dim strValue As String
Set comm = New ADODB.Command
Set cnn = New ADODB.Connection
cnn.ConnectionString = Adodc1.ConnectionString
cnn.CursorLocation = adUseClient
cnn.Open
Set comm.ActiveConnection = cnn
strValue = Trim(txtGrade.Text)
'查询语句中,?代表一个参数
comm.CommandText = "select * from uStudBaseInfo where 所属年级 like ?"
comm.CommandType = adCmdText
'注意,此处,不必用CreateParameter方法,直接按参数集合中的索引号去执行
Set Param = comm.Parameters(0)
Param.Value = strValue
Set rs = comm.Execute
Set DataGrid1.DataSource = rs
End Sub
Private Sub Form_Load()
'picPhoto.DataField = "照片"
Dim strAddSql As String
Dim rsAddInfo As ADODB.Recordset
strAddSql = "select * from uStudInfoAdd"
Set rsAddInfo = GetRecordSet(strAddSql)
'txtNumber.Text = rsAddInfo("学号")
'With dlgOpen
' .Filter = "all|*.*|bmp|*.bmp"
' .ShowSave
' strPath = .FileName
'End With
'Call newGetFromDB(rsAddInfo("照片"), strPath)
'picPhoto.Picture = LoadPicture(strPath)
'Set picPhoto.DataSource = rsAddInfo
Adodc1.CommandType = adCmdTable
'Adodc1.Recordset.Close
' Adodc1.Recordset.Source = "uStudInfoAdd"
' Adodc1.Recordset.Open
Adodc1.RecordSource = "uInfoAdd"
Set picPhoto.DataSource = Adodc1
picPhoto.DataField = "照片"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -