| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 426 人关注过本帖
标题:紧急求助,一个关于参数查询的问题
取消只看楼主 加入收藏
红云
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2005-11-11
收藏
 问题点数:0 回复次数:0 
紧急求助,一个关于参数查询的问题


大伙帮我看看吧,我用了参数查询,就老有错误哦.不用参数,我已经搞定了,但是用了command的parameters后就不对了,请各位帮我看看吧 !先谢过了!
Dim cn As New ADODB.Connection
Dim cmd As New Command

Private Sub Command1_Click()
Dim objrs As Recordset
Dim objsource As Recordset
cmd("sno") = "%" & Text1.Text & "%"
cmd("sn") = "%" & Text2.Text & "%"
cmd("age") = "%" & Text3.Text & "%"
cmd("sex") = "%" & Text4.Text & "%"
cmd("dept") = "%" & Text5.Text & "%"
cmd("dn") = "%" & Text6.Text & "%"
Set objrs = cmd.Execute()
Set objsource = New Recordset
For i = o To objrs.Fields.Count - 1
objsource.Fields.Append objrs.Fields(i).Name, adVarChar, objrs.Fields(i).DefinedSize
Next
objsource.Open
While Not objrs.EOF
objsource.AddNew
objsource!sno = objrs!sno
objsource!sn = objrs!sn
objsource!age = objrs!age
objsource!sex = objrs!sex
objsource!dept = objrs!dept
objsource!dn = objrs!dn
objrs.MoveNext
Wend
If objsource.RecordCount > 0 Then objsource.MoveFirst
Set DataGrid1.DataSource = objsource
End Sub

Private Sub Form_Load()
Set cn = New ADODB.Connection
cn.ConnectionString = "provider=sqloledb.1;data source=(local);user id=sa;pwd=623058;initial catalog=sdb"
cn.Open
Set cmd = New ADODB.Command
cmd.ActiveConnection = cn
With cmd
.CommandText = "select * from s where sno like ? and sn like ? and age like ? and sex like? and dept like ? and dn like ?"
.CommandType = adCmdText
End With
Dim param As New Parameter
Set param = cmd.CreateParameter("sno", adChar, adParamInput, 3)
cmd.Parameters.Append param
Set param = cmd.CreateParameter("sn", adChar, adParamInput, 8)
cmd.Parameters.Append param
Set param = cmd.CreateParameter("age", adInteger, adParamInput, 4)
cmd.Parameters.Append param
Set param = cmd.CreateParameter("sex", adChar, adParamInput, 2)
cmd.Parameters.Append param
Set param = cmd.CreateParameter("dept", adChar, adParamInput, 1)
cmd.Parameters.Append param
Set param = cmd.CreateParameter("dn", adChar, adParamInput, 15)
cmd.Parameters.Append param
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set cmd = Nothing
Set cn = Nothing
End Sub

搜索更多相关主题的帖子: 参数 查询 
2005-11-12 18:30
快速回复:紧急求助,一个关于参数查询的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016251 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved