• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 589
  • Last Modified:

VB Code to execute SQL server stored procedure

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??

Thanks!

-Kunal
0
Kunal_Ghate
Asked:
Kunal_Ghate
1 Solution
 
Melih SARICACommented:
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
mconn.open

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
madap.fill(mdataset)

mdataset.writexml("c:\myxml.xml")



0
 
rodmjayCommented:
MyCommand.CommandType = CommandType.StoredProcedure
myCommand.CommandText = myStoredProcedureName

and once the dataset if full

myDataset.WriteXML(myPath)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now