[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Passing parameter to Stored Procedure

Posted on 2011-09-14
3
Medium Priority
?
316 Views
Last Modified: 2012-06-22
I have the following stored procedure.  I want to pass HTCode from my VB.Net subroutine and then received the values back in a datatable.  Is that possible?  If so, could someone help me out with the code?
ALTER PROCEDURE dbo.HospBillingCodeLoop
	(
	@HTCode varchar(50)
	)
AS
	SELECT * FROM [Hospital Billing Data SQL] WHERE HTCode = @HTCode 
	RETURN

Open in new window

0
Comment
Question by:kshumway
[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
3 Comments
 
LVL 39

Accepted Solution

by:
appari earned 2000 total points
ID: 36540216
try something like this

dim sqlConnect as New System.Data.SqlClient.SqlConnection("connectionString")
sqlConnect.Open()

using ds as new dataset
	using sqlCmd as new SQLCommand()
		sqlCmd.connection = sqlConnect
		sqlCmd.CommandText = "HospBillingCodeLoop"
		sqlCmd.parameters.addwithvalue("@HTCode ","HTCode Value ")
		sqlCommand.CommandType = CommandType.StoredProcedure 
		dim sqlDataAdapter as New System.Data.SqlClient.SqlDataAdapter(sqlCommand)
		sqlDataAdapter.Fill(dataSet)
	end using 
end using 

Open in new window


after the fill satement you will have the returned data in the dataset.
for more info search in books online for keywords like sqldataadapter, dataset, sqlcommand.
for a start http://msdn.microsoft.com/en-us/library/yy6y35y8(VS.80).aspx
0
 
LVL 60

Expert Comment

by:HainKurt
ID: 36540228
something like this:

con.ConnectionString = Settings.ConnectionString("myDB");
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "HospBillingCodeLoop"
cmd.Parameters.Add("@HTCode ", SqlDbType.Int).Value = HTCode;
DataReader dr = cmd.ExecuteReader();
DataSet ds = new Dataset();
ds.Load(dr);
...
0
 

Author Closing Comment

by:kshumway
ID: 36540286
Thank you!  It worked perfectly.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

656 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