VB Code to execute SQL server stored procedure

Posted on 2005-05-06
Last Modified: 2012-05-05
Hi ,

I am pretty new to this.

I have a SQL Server stored (called SP_OESS_Get_Client_Demographics)  procedure that accepts following inputs:
@clientid varchar(10),
@firstname varchar(20),
@lastname varchar(20),
@middlename varchar(10),
@SSN varchar(11),
@Birthdate smalldatetime,
@Gender varchar(1)

and returns an XML result set. I want to know how I can execute this stored procedure using VB.NET. How to do I code it in VB.NET??


Question by:Kunal_Ghate
    LVL 19

    Accepted Solution

    first its not the correct channel.. u ave to ask it in .NET..  

    but here is what u want

    dim mconn as new sqlclient.SQLConnection("Server=servername;username=username;password=password")
    dim mcmd as new SQLclient.SQLCommand
    dim madap as new SQLclient.sqldatadapter
    dim mdataset as dataset

    mcmd.Commandtext = "exec SP_OESS_Get_Client_Demographics @clientid,@firstname,@lastname,@middlename,@SSN,@Birthdate,@Gender "
    mcmd.Connection = mconn

    mcmd.parameters.add (@clientid)
    mcmd.parameters.add (@firstname)
    mcmd.parameters.add (@lastname)
    mcmd.parameters.add (@middlename)
    mcmd.parameters.add (@SSN)
    mcmd.parameters.add (@Birthdate)
    mcmd.parameters.add (@Gender)

    set parameter values

    madap.selectcommand = mcmd


    LVL 8

    Expert Comment

    MyCommand.CommandType = CommandType.StoredProcedure
    myCommand.CommandText = myStoredProcedureName

    and once the dataset if full


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    In this article—a derivative of my blog post (—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
    Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now