主题:再另一个讨论区没问出来,来这里问问。真是奇怪了!
我用是access数据库+VB
数据库data表中,有三个字段。SENSOR 数据类型是:数字;VALUE,数据类型是数字;还有个DATE,数据类型是:日期/时间(短日期)。
data表具体如下:
SENSOR VALUE DATE
1 12.32 07-3-6
1 12.22 07-3-8
2 20.12 07-3-6
1 12.77 07-2-8
..... .... ......
具体要求是:
把日期相同的数据从数据库中提取出来,另寸为文本文件,文件名为查询语句的日期。
我自己写的程序如下。有错误。恳请各位大哥大姐帮帮忙。(给个全代码那就更好了,谢谢)
Option Explicit
Private myconn As New ADODB.Connection
Private myrecord As New ADODB.Recordset
Private Sub Adodc1_WillMove(ByVal adReason As ADODB.EventReasonEnum, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
End Sub
Private Sub Command1_Click()
Dim strsql As String
Set myconn = New ADODB.Connection
myconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\sjcl\df200602.mdb;Persist Security Info=False"
myconn.Open
'strsql = "select * from data where DATE = '" & Text1.Text & "'" 'Text1.text 输入查询日期
(这个地方估计不对)
Set myrecord = New ADODB.Recordset
myrecord.Open strsql, myconn, adOpenDynamic, adLockBatchOptimistic(提示这个地方出错:说是数据类型不匹配。显示代码为2147217913(80040e07).
)
myrecord.MoveFirst
showdata
End Sub
Private Sub showdata()
Open "D:\sjcl\" & Text1.Text & ".txt" For Output As #1
While Not (myrecord.EOF) '未到记录集结尾就继续循环
Print #1, myrecord.Fields(SENSOR_NUM).Value; myrecord.Fields(Value).Value; myrecord.Fields(Date).Value
myrecord.MoveNext '移动到下一条
Wend
Close #1
MsgBox "ok"
End Sub
数据库data表中,有三个字段。SENSOR 数据类型是:数字;VALUE,数据类型是数字;还有个DATE,数据类型是:日期/时间(短日期)。
data表具体如下:
SENSOR VALUE DATE
1 12.32 07-3-6
1 12.22 07-3-8
2 20.12 07-3-6
1 12.77 07-2-8
..... .... ......
具体要求是:
把日期相同的数据从数据库中提取出来,另寸为文本文件,文件名为查询语句的日期。
我自己写的程序如下。有错误。恳请各位大哥大姐帮帮忙。(给个全代码那就更好了,谢谢)
Option Explicit
Private myconn As New ADODB.Connection
Private myrecord As New ADODB.Recordset
Private Sub Adodc1_WillMove(ByVal adReason As ADODB.EventReasonEnum, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
End Sub
Private Sub Command1_Click()
Dim strsql As String
Set myconn = New ADODB.Connection
myconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\sjcl\df200602.mdb;Persist Security Info=False"
myconn.Open
'strsql = "select * from data where DATE = '" & Text1.Text & "'" 'Text1.text 输入查询日期
(这个地方估计不对)
Set myrecord = New ADODB.Recordset
myrecord.Open strsql, myconn, adOpenDynamic, adLockBatchOptimistic(提示这个地方出错:说是数据类型不匹配。显示代码为2147217913(80040e07).
)
myrecord.MoveFirst
showdata
End Sub
Private Sub showdata()
Open "D:\sjcl\" & Text1.Text & ".txt" For Output As #1
While Not (myrecord.EOF) '未到记录集结尾就继续循环
Print #1, myrecord.Fields(SENSOR_NUM).Value; myrecord.Fields(Value).Value; myrecord.Fields(Date).Value
myrecord.MoveNext '移动到下一条
Wend
Close #1
MsgBox "ok"
End Sub