四、 文件存取
1.文件写入数据库的实例
Dim cn0 As ADODB.Connection '定义连接
Dim rs0 As ADODB.Recordset '定义记录集
Dim strcn0 As String
Private Sub Combo1_LostFocus()
If Combo1.Text = "综合" Then Text1 = "2972901"
If Combo1.Text = "酸轧" Then Text1 = "2972902"
If Combo1.Text = "连退" Then Text1 = "2972903"
If Combo1.Text = "热镀锌1" Then Text1 = "2972904"
If Combo1.Text = "热镀锌2" Then Text1 = "2972905"
If Combo1.Text = "彩涂" Then Text1 = "2972906"
If Combo1.Text = "精整" Then Text1 = "2972907"
If Combo1.Text = "其它" Then Text1 = "2972908"
Combo2.Enabled = True
End Sub
If Combo2.Text = "综合类" Then Text1 = Text1 & "01"
If Combo2.Text = "总图、运输" Then Text1 = Text1 & "02"
If Combo2.Text = "工艺" Then Text1 = Text1 & "03"
If Combo2.Text = "土建" Then Text1 = Text1 & "04"
If Combo2.Text = "给排水" Then Text1 = Text1 & "05"
If Combo2.Text = "采暖、通风" Then Text1 = Text1 & "06"
If Combo2.Text = "热力燃气" Then Text1 = Text1 & "07"
If Combo2.Text = "计控、电讯" Then Text1 = Text1 & "08"
If Combo2.Text = "供电、电气" Then Text1 = Text1 & "09"
If Combo2.Text = "设备、设备安装" Then Text1 = Text1 & "10"
If Combo2.Text = "其它专业" Then Text1 = Text1 & "11"
Combo2.Enabled = False
Dim a1, a2 As String
a2 = "000"
If rs0.State = adStateOpen Then rs0.Close
rs0.Open "SELECT * FROM 资料信息 " & _
"WHERE 文件编号 like '%" & Trim(Text1) & "%' order by 文件编号", strcn0, , , adCmdText '选择条件
Do While Not rs0.EOF
a1 = Mid(rs0!文件编号, 10, 3)
If a2 <= a1 Then a2 = a1
rs0.MoveNext
Loop
rs0.Close
Dim s1 As String
If a2 + 1 < 10 Then s1 = "00" & a2 + 1
If a2 + 1 >= 10 And a2 + 1 < 100 Then s1 = "0" & a2 + 1
If a2 + 1 >= 100 And a2 + 1 < 1000 Then s1 = a2 + 1
Text1 = Mid(Text1, 1, 9) & s1
End Sub
Private Sub Command1_Click()
If Trim(Text1) = "" Then
MsgBox "此文件编号不允许为空!", vbOKOnly + vbCritical, "警告"
Exit Sub
End If
'查看此文件是否存在
If Trim(Text5) <> "" Then
Dim astr As String
astr = Dir(Text5 & Text4)
If astr = "" Then
MsgBox "此文件不在指定的文件夹里,请核对!", vbOKOnly, "提示"
Exit Sub
End If
|