How to execute a Stored Procedure using ADO.Net 
Author Message
 How to execute a Stored Procedure using ADO.Net

I want to find out how to set the parameters (In / Out) and execute a SQL
Server Stored Procedure using the following 2 methods in .Net environment
using ADO.Net.

1. ADOCommand / ADOConnection

2. SQLDataSetCommand / SQLConnection

The Stored Procedure will have In / Out parameters and return data
(records). It will have the following structure:


Select * From MyTable




The procedure also returns data from the statement (Select * From MyTable).

Thanks

Giri



Wed, 13 Aug 2003 08:04:02 GMT  
 How to execute a Stored Procedure using ADO.Net
Basically you create a connection first, then create the SQLDataSetCommand
on that connection, add parameters one by one and set their direction, data
type. Finally create a dataset or datatable and fill them with the result
returned from stored proc.

check microsoft.public.dotnet.framework.adonet. or http://www.gotdotnet.com
There are many examples there.

- Chu


Quote:
> I want to find out how to set the parameters (In / Out) and execute a SQL
> Server Stored Procedure using the following 2 methods in .Net environment
> using ADO.Net.

> 1. ADOCommand / ADOConnection

> 2. SQLDataSetCommand / SQLConnection

> The Stored Procedure will have In / Out parameters and return data
> (records). It will have the following structure:


> Select * From MyTable





> The procedure also returns data from the statement (Select * From
MyTable).

> Thanks

> Giri



Wed, 13 Aug 2003 12:28:12 GMT  
 How to execute a Stored Procedure using ADO.Net
Giri

Quote:
> I want to find out how to set the parameters (In / Out) and execute a SQL
> Server Stored Procedure using the following 2 methods in .Net environment
> using ADO.Net.

Below is some code for you. It only demonstrates 'In' params. I hope it
helps.

Jonny

----------
    Private mSQL As SQLDataSetCommand

    'Stored procedure parameter names


    Private Const TABLE_NAME = "tblMember"
    Private Const SQL_CONNECT =
"server=localhost;PersistSecurityInfo=false;User ID=sa;database=MyDBName"

    Public Sub New()
        MyBase.New()
        'Create the DataSetCommand
        mSQL = New SQLDataSetCommand()
        mSQL.TableMappings.Add("Table",TABLE_NAME)
    End Sub

    Public Function GetMember(ByVal LogName As String, ByVal LogPassword As
String) As MemberData
        Dim Data As New MemberData()
        Dim SPROC As New SQLCommand("GetMember", New
SQLConnection(SQL_CONNECT))

        'Initialize the parameterized SPROC command object
        With SPROC
            .CommandType = CommandType.StoredProcedure
            'Attach SPROC parameters
            .Parameters.Add(New SQLParameter(PARM_LOGNAME,
SQLDataType.NVarChar, 50))
            .Parameters.Add(New SQLParameter(PARM_LOGPASSWORD,
SQLDataType.NVarChar, 50))
        End With

        'Retrieves the Member
        With mSQL
            .SelectCommand = SPROC
            .SelectCommand.Parameters(PARM_LOGNAME).Value = LogName
            .SelectCommand.Parameters(PARM_LOGPASSWORD).Value = LogPassword
            .FillDataSet(Data, Data.TABLE_MEMBER)
        End With
        Return Data

    End Function



Fri, 29 Aug 2003 05:44:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problem with executing stored procedures using ADO

2. Problem with executing stored procedures using ADO

3. executing a stored procedure in oracle using ADO

4. VB.Net => Ado.Net = Stored Procedure

5. ADO executing oracle stored procedure/function

6. ADO 1.5 CMD error when executing Stored Procedures??

7. problem in executing an Oracle stored procedure by ADO

8. VB6 ADO Stored Procedure Execute

9. Execute a Fox's store procedure with ADO

10. ado recordsets from stored procedures, stored procedures have input parameters

11. Executing a Stored Procedure via ADO hangs the PC

12. Executing a Stored Procedure via ADO hangs the PC

 

 
Powered by phpBB® Forum Software