求大神帮忙看看,以前的老程序 问题多多啊
--------------------编程问答-------------------- 提示什么,如果使用DBF,为什么用ADO连接? --------------------编程问答-------------------- cn0.Execute "pack JTalarm"改为
cn0.Execute "pack" --------------------编程问答-------------------- Option Explicit
Dim cn As ADODB.Connection
Dim cn0 As ADODB.Connection
Dim rst As ADODB.Recordset
Dim rst0 As ADODB.Recordset
Private Sub cmdcancel_Click()
Unload Me
End
End Sub
Private Sub cmdsure_Click()
Dim st_date As String
'case 10
If Len(DTPicker1.value) = 10 And Mid(DTPicker1.value, 5, 1) = "-" And Mid(DTPicker1.value, 8, 1) = "-" Then
st_date = Mid(DTPicker1.value, 6, 2) + "/" + Right(DTPicker1.value, 2) + "/" + Mid(DTPicker1.value, 3, 2)
End If
'case 8
If Len(DTPicker1.value) = 8 And Mid(DTPicker1.value, 5, 1) = "-" And Mid(DTPicker1.value, 7, 1) = "-" Then
st_date = "0" + Mid(DTPicker1.value, 6, 1) + "/" + "0" + Right(DTPicker1.value, 1) + "/" + Mid(DTPicker1.value, 3, 2)
End If
'case 9_1
If Len(DTPicker1.value) = 9 And Mid(DTPicker1.value, 5, 1) = "-" And Mid(DTPicker1.value, 8, 1) = "-" Then
st_date = Mid(DTPicker1.value, 6, 2) + "/" + "0" + Right(DTPicker1.value, 1) + "/" + Mid(DTPicker1.value, 3, 2)
End If
'case 9_2
If Len(DTPicker1.value) = 9 And Mid(DTPicker1.value, 5, 1) = "-" And Mid(DTPicker1.value, 7, 1) = "-" Then
st_date = "0" + Mid(DTPicker1.value, 6, 1) + "/" + "0" + Right(DTPicker1.value, 2) + "/" + Mid(DTPicker1.value, 3, 2)
End If
If DTPicker1.value > Date Then
MsgBox "对不起,您选择的表不存在!", , "信息提示"
Else
'生成数据中的表明
Dim st_biaoming As String
'case 10
If Len(DTPicker1.value) = 10 And Mid(DTPicker1.value, 5, 1) = "-" And Mid(DTPicker1.value, 8, 1) = "-" Then
st_biaoming = Mid(DTPicker1.value, 3, 2) + Mid(DTPicker1.value, 6, 2) + Right(DTPicker1, 2)
End If
'case 8
If Len(DTPicker1.value) = 8 And Mid(DTPicker1.value, 5, 1) = "-" And Mid(DTPicker1.value, 7, 1) = "-" Then
st_biaoming = Mid(DTPicker1.value, 3, 2) + "0" + Mid(DTPicker1.value, 6, 1) + "0" + Right(DTPicker1.value, 1)
End If
'case 9_1
If Len(DTPicker1.value) = 9 And Mid(DTPicker1.value, 5, 1) = "-" And Mid(DTPicker1.value, 8, 1) = "-" Then
st_biaoming = Mid(DTPicker1.value, 3, 2) + Mid(DTPicker1.value, 6, 2) + "0" + Right(DTPicker1.value, 1)
End If
'case 9_2
If Len(DTPicker1.value) = 9 And Mid(DTPicker1.value, 5, 1) = "-" And Mid(DTPicker1.value, 7, 1) = "-" Then
st_biaoming = Mid(DTPicker1.value, 3, 2) + "0" + Mid(DTPicker1.value, 6, 1) + Right(DTPicker1.value, 2)
End If
Set cn = New ADODB.Connection
Set cn0 = New ADODB.Connection
Set rst = New ADODB.Recordset
Set rst0 = New ADODB.Recordset
cn.Open "dsn=ALG;uid=;pwd;"
cn0.Open "dsn=yanchang;uid=;pwd;"
rst0.Open "select * from JTalarm", cn0, adOpenStatic, adLockOptimistic
If ComboBox1.value = "3" Then
rst.Open "select Date,Time,Transtype,Tagname,severity from " + st_biaoming + "AL" + " where(severity=3)" + " order by Time desc", cn, adOpenStatic, adLockOptimistic
End If
If ComboBox1.value = "2" Then
rst.Open "select Date,Time,Transtype,Tagname,severity from " + st_biaoming + "AL" + " where(severity=2)" + " order by Time desc", cn, adOpenStatic, adLockOptimistic
End If
If ComboBox1.value = "1" Then
rst.Open "select Date,Time,Transtype,Tagname,severity from " + st_biaoming + "AL" + " where(severity=1)" + " order by Time desc", cn, adOpenStatic, adLockOptimistic
End If
If ComboBox1.value = "All" Then
rst.Open "select Date,Time,Transtype,Tagname,severity from " + st_biaoming + "AL" + " order by Time desc", cn, adOpenStatic, adLockOptimistic
End If
'If ComboBox1.value = "3" Then
'rst.Open "select Date,Time,Transtype,Tagname,severity from " + st_biaoming + "AL" + " where(severity=3)", cn, adOpenStatic, adLockOptimistic
'End If
'If ComboBox1.value = "2" Then
'rst.Open "select Date,Time,Transtype,Tagname,severity from " + st_biaoming + "AL" + " where(severity=2)", cn, adOpenStatic, adLockOptimistic
'End If
'If ComboBox1.value = "1" Then
'rst.Open "select Date,Time,Transtype,Tagname,severity from " + st_biaoming + "AL" + " where(severity=1)", cn, adOpenStatic, adLockOptimistic
'End If
'If ComboBox1.value = "All" Then
'rst.Open "select Date,Time,Transtype,Tagname,severity from " + st_biaoming + "AL", cn, adOpenStatic, adLockOptimistic
'End If
Dim i As Integer
For i = 1 To rst.RecordCount
rst0.AddNew
rst0.Fields("日期") = rst.Fields("Date")
rst0.Fields("时间") = rst.Fields("Time")
rst0.Fields("报警级") = rst.Fields("Severity")
rst0.Fields("状态") = rst.Fields("Transtype")
rst0.Fields("标记名") = Trim(rst.Fields("Tagname"))
rst0.Fields("描述") = gTagDb.GetTag(Trim(rst.Fields("Tagname"))).Description
rst0.Update
rst.MoveNext
Next i
Set rst = Nothing
Set rst0 = Nothing
Set cn = Nothing
Set cn0 = Nothing
End If
'读取并显示
Set cn = New ADODB.Connection
Set rst = New ADODB.Recordset
cn.Open "dsn=yanchang;uid=;pwd;"
rst.Open "select * from JTalarm", cn, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = Nothing
Set DataGrid1.DataSource = rst
Set rst = Nothing
Set cn = Nothing
'删除
Set cn0 = New ADODB.Connection
Set rst0 = New ADODB.Recordset
cn0.Open "dsn=yanchang;uid=;pwd;"
rst0.Open "select * from JTalarm", cn0, adOpenStatic, adLockOptimistic
If rst0.RecordCount >= 1 Then
cn0.Execute "delete from JTalarm"
End If
Set rst0 = Nothing
Set cn0 = Nothing
End Sub
Private Sub Frame1_Click()
End Sub
Private Sub UserForm_Initialize()
'真删除
Set cn0 = New ADODB.Connection
Set rst0 = New ADODB.Recordset
cn0.Open "dsn=yanchang;uid=;pwd;"
'rst0.Open "select * from JTalarm", cn, adOpenStatic, adLockOptimistic
cn0.Execute "pack JTalarm"
Set rst0 = Nothing
Set cn0 = Nothing
DTPicker1.value = Date
'Set cn = New ADODB.Connection
'Set rst = New ADODB.Recordset
'cn.Open "dsn=ALG;uid=;pwd;"
'rst.Open "select * from JTalarm", cn, adOpenStatic, adLockOptimistic
'Set DataGrid1.DataSource = rst
'Set rst = Nothing
'Set cn = Nothing
ComboBox1.AddItem "All"
ComboBox1.AddItem 1
ComboBox1.AddItem 2
ComboBox1.AddItem 3
ComboBox1.ListIndex = 0
End Sub
完整代码。。我看了 是连接ODBC那个数据源 连接的VFP数据库。。 --------------------编程问答-------------------- 你这是 VB 的程序?
先检查一下数据源是否存在并有效 --------------------编程问答-------------------- 数据源没的问题。。因为其他调用都可以运行。。
补充:VB , 数据库(包含打印,安装,报表)