请大家帮我看看为什么我用这条sql语句查询不到access数据库的数据表中的一条记录?
DimpolicemanAsIntegerDimKuvaszAsStringpoliceman=InputBox("请输入查询编号!","输入编号进行查询",1)Kuva...
Dim policeman As Integer
Dim Kuvasz As String
policeman = InputBox("请输入查询编号!", "输入编号进行查询", 1)
Kuvasz = "SELECT 编号 from Temresult where 编号=" & policeman
Call OpenAdoRecordset(Kuvasz, vsoReco)
enquiry.Label21.Caption = policeman
enquiry.Label3.Caption = vsoReco.Fields("台区名称").Value
enquiry.Label5.Caption = vsoReco.Fields("总供电量").Value
其中openAdoRecordset是:
Public Sub OpenAdoRecordset(ByVal strSQL As String, vsoReco As ADODB.Recordset)
Dim vsoConn As ADODB.Connection
Dim strcnn As String
Set vsoConn = New ADODB.Connection
Set vsoReco = New ADODB.Recordset
strcnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\WW\data.mdb"
vsoConn.Open strcnn
Set vsoReco.ActiveConnection = vsoConn
vsoReco.CursorType = adOpenStatic
vsoReco.LockType = adLockOptimistic
vsoReco.Open strSQL
End Sub
数据表Temresult的编号字段是整型,按编号查询到一条指定的记录。 展开
Dim Kuvasz As String
policeman = InputBox("请输入查询编号!", "输入编号进行查询", 1)
Kuvasz = "SELECT 编号 from Temresult where 编号=" & policeman
Call OpenAdoRecordset(Kuvasz, vsoReco)
enquiry.Label21.Caption = policeman
enquiry.Label3.Caption = vsoReco.Fields("台区名称").Value
enquiry.Label5.Caption = vsoReco.Fields("总供电量").Value
其中openAdoRecordset是:
Public Sub OpenAdoRecordset(ByVal strSQL As String, vsoReco As ADODB.Recordset)
Dim vsoConn As ADODB.Connection
Dim strcnn As String
Set vsoConn = New ADODB.Connection
Set vsoReco = New ADODB.Recordset
strcnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\WW\data.mdb"
vsoConn.Open strcnn
Set vsoReco.ActiveConnection = vsoConn
vsoReco.CursorType = adOpenStatic
vsoReco.LockType = adLockOptimistic
vsoReco.Open strSQL
End Sub
数据表Temresult的编号字段是整型,按编号查询到一条指定的记录。 展开
1个回答
展开全部
Kuvasz = "SELECT 编号 from Temresult where 编号=" & policeman
enquiry.Label3.Caption = vsoReco.Fields("台区名称").Value
enquiry.Label5.Caption = vsoReco.Fields("总供电量").Value
--------------------------------
更改为
Kuvasz = "SELECT 台区名称字段名, 总供电量字段名 from Temresult where 编号=" & policeman
enquiry.Label3.Caption = vsoReco.Fields(0).Value
enquiry.Label5.Caption = vsoReco.Fields(1).Value
enquiry.Label3.Caption = vsoReco.Fields("台区名称").Value
enquiry.Label5.Caption = vsoReco.Fields("总供电量").Value
--------------------------------
更改为
Kuvasz = "SELECT 台区名称字段名, 总供电量字段名 from Temresult where 编号=" & policeman
enquiry.Label3.Caption = vsoReco.Fields(0).Value
enquiry.Label5.Caption = vsoReco.Fields(1).Value
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询