Vb.net Coding to call Stored Procedures

  • Hi friends ..

    Can you tel me how to call stored procedures through vb.net coding..

    Thanks and Regards

    Shobana

  • You would do something like this:

    Imports System.Data.SQLClient

    Dim cnSQL as SQLConnection = New SQLConnection(ConnectionString)

    Dim cmdSQL as new SQLCommand

    ' if you want to return results using a datareader then you need a SQLDataReader

    Dim dr as SQLDataReader

    ' if you want to return results using a dataset/datatable then you need a SQLDataAdapter

    ' and a dataset or datatable

    Dim da as SQLDataAdapter = New SQLDataAdapter(cmdSQL)

    Dim ds as DataSet

    ' if you are not returning data then you do not need anything else

    With cmdSQL

    .Connection = cnSQL

    .CommandType = storedprocedure

    .CommandText = "stored procedure name"

    ' now add parameters

    .Parameters.AddWithValue("parameter name", value)

    ' open the connection

    cnSQL.Open()

    ' for a procedure that returns no resultset

    .ExecuteNonQuery()

    ' for a procedure to return a datareader (you need to create the

    drSQL = .ExecuteDataReader()

    ' to return a dataset

    da.Fill(ds)

    End With

    Edited to remove the horizontal scroll (at least on my screen):w00t:

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply