一个函数,谁能告诉我错误在那里??(在线等待!)

jonaslee 2004-08-11 04:42:57
Private Sub fillcontrols()
Dim tmpstr As String
Dim rs As New ADODB.Connection
Set rs = Nothing
On Error GoTo Destory
tmpstr = "select * from customer where telephone1=" & TransSQLChar(Trim(m_telephone)) & _
" or telephone2=" & TransSQLChar(Trim(m_telephone)) & _
" or fax=" & TransSQLChar(Trim(m_telephone))
Set rs = pADO.Connection.Execute(tmpstr, , adCmdText)
MsgBox "victory", vbExclamation, ""
txtCustomer.Text = "" & rs!CustomerID -----------显示是此处的“rs”出问题!
txtCustomerName.Text = "" & rs!DescC
txtAddress.Text = "" & rs!AddressC
txtZJR.Text = "" & rs!zjjr
txtflfs.Text = "" & rs!flxz
txtjsyq.Text = "" & rs!jsyq
txtSFBZ.Text = "" & rs!tcsfbz
txtTSJG.Text = "" & rs!tsjg
txtbl.Text = "" & rs!bxbl
txtysfs.Text = "" & rs!ysfs
txtRemark.Text = "" & rs!Remark
txttime.Text = "" & rs!foundtime


Destory:
MsgBox Err.Description, vbCritical, "提示"
End Sub

执行的时候,错误提示:
错误的参数号或无效的属性设置!
...全文
138 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
bubu198 2004-08-12
  • 打赏
  • 举报
回复
'Execute、Requery、Clear方法的例

Public Sub ExecuteX()

Dim strSQLChange As String
Dim strSQLRestore As String
Dim strCnn As String
Dim cnn1 As ADODB.Connection
Dim cmdChange As ADODB.Command
Dim rstTitles As ADODB.Recordset
Dim errLoop As ADODB.Error

' Define two SQL statements to execute as command text.
strSQLChange = "UPDATE Titles SET Type = " & _
"'self_help' WHERE Type = 'psychology'"
strSQLRestore = "UPDATE Titles SET Type = " & _
"'psychology' WHERE Type = 'self_help'"

' Open connection.
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=Pubs;User Id=sa;Password=; "
Set cnn1 = New ADODB.Connection
cnn1.Open strCnn

' Create command object.
Set cmdChange = New ADODB.Command
Set cmdChange.ActiveConnection = cnn1
cmdChange.CommandText = strSQLChange

' Open titles table.
Set rstTitles = New ADODB.Recordset
rstTitles.Open "titles", cnn1, , , adCmdTable

' Print report of original data.
Debug.Print _
"Data in Titles table before executing the query"
PrintOutput rstTitles

' Clear extraneous errors from the Errors collection.
cnn1.Errors.Clear

' Call the ExecuteCommand subroutine to execute cmdChange command.
ExecuteCommand cmdChange, rstTitles

' Print report of new data.
Debug.Print _
"Data in Titles table after executing the query"
PrintOutput rstTitles

' Use the Connection object's execute method to
' execute SQL statement to restore data. Trap for
' errors, checking the Errors collection if necessary.
On Error GoTo Err_Execute
cnn1.Execute strSQLRestore, , adExecuteNoRecords
On Error GoTo 0

' Retrieve the current data by requerying the recordset.
rstTitles.Requery

' Print report of restored data.
Debug.Print "Data after executing the query " & _
"to restore the original information"
PrintOutput rstTitles

rstTitles.Close
cnn1.Close

Exit Sub

Err_Execute:

' Notify user of any errors that result from
' executing the query.
If rstTitles.ActiveConnection.Errors.Count >= 0 Then
For Each errLoop In rstTitles.ActiveConnection.Errors
MsgBox "Error number: " & errLoop.Number & vbCr & _
errLoop.Description
Next errLoop
End If
Resume Next

End Sub

Public Sub ExecuteCommand(cmdTemp As ADODB.Command, _
rstTemp As ADODB.Recordset)

Dim errLoop As Error

' Run the specified Command object. Trap for
' errors, checking the Errors collection if necessary.
On Error GoTo Err_Execute
cmdTemp.Execute
On Error GoTo 0

' Retrieve the current data by requerying the recordset.
rstTemp.Requery

Exit Sub

Err_Execute:

' Notify user of any errors that result from
' executing the query.
If rstTemp.ActiveConnection.Errors.Count > 0 Then
For Each errLoop In Errors
MsgBox "Error number: " & errLoop.Number & vbCr & _
errLoop.Description
Next errLoop
End If

Resume Next

End Sub

Public Sub PrintOutput(rstTemp As ADODB.Recordset)

' Enumerate Recordset.
Do While Not rstTemp.EOF
Debug.Print " " & rstTemp!Title & _
", " & rstTemp!Type
rstTemp.MoveNext
Loop

End Sub

TNT1900 2004-08-12
  • 打赏
  • 举报
回复
你都没判断RS是不是NOTHING,也没看有没有数据。
你应该先作如下判断:
1)ISNothing(RS);--如果取数据出错;
2)IF RS.Bof AND RS.Eof --如果没有数据;
给我的感觉好象是没有查找大有符合条件的记录,如果“MsgBox "victory", vbExclamation, ""
”实现了的话。
zhangzhijian 2004-08-12
  • 打赏
  • 举报
回复
tmpstr 出错!
tmpstr = "select * from customer where telephone1='" & TransSQLChar(Trim(m_telephone)) & _
"'or telephone2='" & TransSQLChar(Trim(m_telephone)) & _
"'or fax='" & TransSQLChar(Trim(m_telephone))& "'"
zhangzhijian 2004-08-12
  • 打赏
  • 举报
回复
sql语句写错了!
kolacana 2004-08-12
  • 打赏
  • 举报
回复
定义一个记录集然后要给里面读入数据库表的数据,
再调用记录集的字段进行赋值,试试
lj77916 2004-08-12
  • 打赏
  • 举报
回复
没有定义的记录集Recordset
定义一个recordset对象
为rst
然后将你的 Set rs = pADO.Connection.Execute(tmpstr, , adCmdText)
改为set rst=rs.(tmpstr)
落伍者 2004-08-11
  • 打赏
  • 举报
回复
把select * from
改成把每个字段都写全
lgs666 2004-08-11
  • 打赏
  • 举报
回复

Dim rs As New ADODB.Connection
改为:
Dim rs As New ADODB.recordset
lgs666 2004-08-11
  • 打赏
  • 举报
回复

Set rs = pADO.Connection.Execute(tmpstr, , adCmdText)
改为:
Set rs = pADO.Connection.Execute(tmpstr)
wxrwan 2004-08-11
  • 打赏
  • 举报
回复
On Error GoTo Destory 去掉后调试
直接查看值
starsoulxp 2004-08-11
  • 打赏
  • 举报
回复
//Dim rs As New ADODB.Connection


你定义的记录集Recordset呢?
啊呀 2004-08-11
  • 打赏
  • 举报
回复
On Error GoTo Destory 去掉后调试
还有你的TransSQLChar()函数 也去掉 on error
啊呀 2004-08-11
  • 打赏
  • 举报
回复
察看一下 rs!CustomerID 的值不就知道了么
jonaslee 2004-08-11
  • 打赏
  • 举报
回复
怎么可能呢!
字段应该没有问题的。
需要说明的是。
m_telephone是一个变量。
benjamin8064 2004-08-11
  • 打赏
  • 举报
回复
是不是表中没有该字段呀CustomerID或者没有txtCustomer文本框

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧