?
Solved

VB6: How to call SQLServer 2000 system procedure sp_fkeys

Posted on 2004-09-01
4
Medium Priority
?
223 Views
Last Modified: 2013-12-25
This is a frustrating one.  If I use "sp_fkeys 'tblControl'" in Query Analzyer, I get the information I'm after (relationships the table is participating in).  HOW do I call this stored procedure from VB6?? It's driving me nuts!

I've tried the code below (which I got off the web somewhere) and passed in "sp_fkeys" and "tblControl".  I don't get any errors, but the recordset has no records in it.  When I run it through Query Analyser, 3 records return (which is correct, since the table is participating in three relationships):

Public Function CallStoredProc(sProcName As String, sParameter As String) As Integer
    'TH 22/01/01 call a stored procedure from vb
    Dim cmd As New Command
    Dim prm As New ADODB.Parameter
    Dim rs As New ADODB.Recordset
    'create new stored proc object
    Set cmd = New ADODB.Command
    'add a paramter with value of "sParameter"
    Set prm = cmd.CreateParameter("param1", adBSTR, adParamInput, 1, sParameter)

    With cmd
        .Parameters.Append prm
        .ActiveConnection = gcn
        .CommandType = adCmdStoredProc
        .CommandText = sProcName
    End With
   
    Set rs = cmd.Execute
   
    If Not rs.State = adStateOpen Then
        rs.Open
    End If
    If gcn.Errors.Count > 0 Then
        MsgBox gcn.Errors.Item(0)
    End If
    'Set frmMain.list1.DataSource = rs
    MsgBox rs.RecordCount
End Function
0
Comment
Question by:MushyPeas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 29

Accepted Solution

by:
leonstryker earned 1000 total points
ID: 11963339
Hmm, try this:

Public Function CallStoredProc(sProcName As String, sParameter As String) As Integer
Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    rs.Open "Exec " & sProcName & "'" & sParameter & "'"
    MsgBox rs.RecordCount
    CallStoredProc = rs.RecordCount
End Function


Leon
0
 
LVL 1

Author Comment

by:MushyPeas
ID: 11969268
Thank you!!!  Can you explain this to me - why "Exec".  Is this not the same as saying cmd.execute (which I also tried)

Is this an acceptable/efficient/safe method to use?

Thanks

M
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question