ming said:
Here is my code in Access:
Set conn = New ADODB.Connection
Set cmd = New ADODB.Command
Set rs = New ADODB.Recordset
conn.Open "Provider=SQLOLEDB.1;Password=;Persist
security Info=False;User ID=;Initial Catalog=lab;Data
Source="
With cmd
.ActiveConnection = conn
.CommandType = adCmdStoredProc
.CommandText = "searchname"
End With
Dim prm As ADODB.Parameter
Set prm = cmd.CreateParameter("@lname", adChar,
adParamInput, 50, lname)
cmd.Parameters.Append prm
Set prm = cmd.CreateParameter("@fname", adChar,
adParamInput, 50, fname)
cmd.Parameters.Append prm
Set rs = cmd.Execute
I can't get any records from rs.
Thanks.
Hmm, I'm no great expert on ADO, but the only thing I see wrong in that
code is the line
Set rs = New ADODB.Recordset
I don't think this line serves any purpose, since you're not going to
use that Recordset object variable until you set it to the recordset
created by cmd. I'd delete that line.
I don't see, though, how that would keep you from getting any records
back in the recordset returned by cmd. Questions:
1. Have you verified that cmd executed successfully?
2. Is a recordset actually returned by cmd?
3. How have you verified that the recordset is empty?
4. Are you sure that the variables (or control references) lname and
fname have the values you think they do, and that these values should
cause the stored procedure "searchname" to return records?
5. If you execute the stored procedure directly with those parameters
via, say SQL Query Analyzer, does it return records?
6. Have you checked the connection's Errors collection after executing
cmd, to see if there's any error reported there?