473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how do I call a SQL Server stored procedure?

cj
I need to call a stored procedure that passes back 2 strings. I don't
think I need a data adapter or a select command or a command builder.
So after I create the connection what do I do?

Dim mySqlConnection As New SqlConnection
mySqlConnection.ConnectionString = conStr
?
?
?

Mar 10 '06 #1
11 15967
how is it passing back strings? in parameters or in a table? if its a table
with multiple rows or columns you need a data adapter.... if it is using
output parameters you need only a command object with the parameters its
coming back marked as output direction.

dim cmd as sqlclient.sqlcommand("SP_Proc",databasecon)

cmd.commandtype = commandtypes.storedprocedure

cmd.parameters.add("@retstring1",nvarchar(100))
cmd.parameters("@retstring1").direction = output

cmd.executenonquery()

debug.writeline(cmd.paramter("@restring1").value.t ostring)

that isnt entirely the correct names and methods but that should show you
what to do to get an output param back if that is how you are doing it
Mar 10 '06 #2
cj
I wrote it out like you showed but haven't been able to work a bug out
of it. When I have 2 parameters added (the stored procedure returns 2
strings, it doesn't take anything), I'm trapping an error "Procedure
priority_high has no parameters and arguments were supplied.

If I remark out the two parameters.add lines and run it, it passes the
executenonquery line and when I go to display in a message box the 2
strings It's supposed to return I trap the error "An sqlparameter with
parametername '@mBTN' is not contianed by this SqlParameter Collection."

Any ideas?

Code snipit

Dim HighSqlCommand As New SqlClient.SqlCommand
HighSqlCommand.Connection = mySqlConnection
HighSqlCommand.CommandType = CommandType.StoredProcedure
HighSqlCommand.CommandText = "priority_high"
HighSqlCommand.Parameters.Add("@mBTN", SqlDbType.Char = 6)
HighSqlCommand.Parameters.Add("@mUID", SqlDbType.Char = 10)

mySqlConnection.Open()
Try
HighSqlCommand.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Execute error: " & ex.Message)
End Try

mySqlConnection.Close()

Try
MessageBox.Show(HighSqlCommand.Parameters("@mBTN") .ToString
& " " & HighSqlCommand.Parameters("@mUID").ToString)
Catch ex As Exception
MessageBox.Show("MessageBox error: " & ex.Message)
End Try
Brian Henry wrote:
how is it passing back strings? in parameters or in a table? if its a table
with multiple rows or columns you need a data adapter.... if it is using
output parameters you need only a command object with the parameters its
coming back marked as output direction.

dim cmd as sqlclient.sqlcommand("SP_Proc",databasecon)

cmd.commandtype = commandtypes.storedprocedure

cmd.parameters.add("@retstring1",nvarchar(100))
cmd.parameters("@retstring1").direction = output

cmd.executenonquery()

debug.writeline(cmd.paramter("@restring1").value.t ostring)

that isnt entirely the correct names and methods but that should show you
what to do to get an output param back if that is how you are doing it

Mar 10 '06 #3
See this link http://www.vbdotnetheaven.com/Code/Jun2003/2102.asp
By the way ExecuteNonQuery is for "action" querries - those that don't
return any data but instead perform an action.
If you are just starting to work with stored procedures in vb.net
forget about using output parameters. Make the stored procedure return
a row of data and use that to populate a dataset or datatable in
vb.net. The link above can help with that.
Hope this helps.
Bishop

Mar 10 '06 #4
cj
I'll look at the link soon. We ended up combining the two fields being
returned into one within the stored procedure and then we can pick it up
with execute scalar. I'm not really interested in returning a dataset.
I just want 2 short stings. I'd love to figure out how to get those
returned with out going in to datasets.

bishop wrote:
See this link http://www.vbdotnetheaven.com/Code/Jun2003/2102.asp
By the way ExecuteNonQuery is for "action" querries - those that don't
return any data but instead perform an action.
If you are just starting to work with stored procedures in vb.net
forget about using output parameters. Make the stored procedure return
a row of data and use that to populate a dataset or datatable in
vb.net. The link above can help with that.
Hope this helps.
Bishop

Mar 10 '06 #5
Hi CJ,

Thanks for your post!

From your description, my understanding is that the current stored
procedure uses the select statement and returns one row which contains two
columns. If I have misunderstood anything, please let me know.

If you don't want to use the DataAdapter with the DataSet, I suggest you
use the DataReader to instead of the DataAdapter. The following article
from MSDN demonstrates how to use the DataReader :
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpcontheadonetdatareader.asp

If the stored procedure uses the output parameter as the returned value,
Brian's suggestion is appropriated.

Hope this will be helpful!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Mar 13 '06 #6
hi cj,

have you tried setting your parameters' direction to output.

diego

Mar 13 '06 #7
cj
We were using the output parameter but never could get Brian's method to
work. We switched to putting to two fields into one variable and using
the select method with execute scalar.
Yuan Ren[MSFT] wrote:
Hi CJ,

Thanks for your post!

From your description, my understanding is that the current stored
procedure uses the select statement and returns one row which contains two
columns. If I have misunderstood anything, please let me know.

If you don't want to use the DataAdapter with the DataSet, I suggest you
use the DataReader to instead of the DataAdapter. The following article
from MSDN demonstrates how to use the DataReader :
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpcontheadonetdatareader.asp

If the stored procedure uses the output parameter as the returned value,
Brian's suggestion is appropriated.

Hope this will be helpful!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Mar 13 '06 #8
hi cj,

i mean the parameter direction in your program as brian has showed.
cmd.parameters.add("@retstring1",nvarchar(100))
cmd.parameters("@retstring1").direction = output <---- this line


hth,
diego

Mar 13 '06 #9
cj
I believe we did catch that but if I remember correctly it started
giving us True True. We're not sure why as we were expecting to see
000001 2326678295

diego wrote:
hi cj,

have you tried setting your parameters' direction to output.

diego

Mar 13 '06 #10
cj
I believe we did catch that but if I remember correctly it started
giving us True True. We're not sure why as we were expecting to see
000001 2326678295
diego wrote:
hi cj,

i mean the parameter direction in your program as brian has showed.
cmd.parameters.add("@retstring1",nvarchar(100))
cmd.parameters("@retstring1").direction = output <---- this line


hth,
diego

Mar 13 '06 #11
hi cj,

i think the problem is with the following lines:

HighSqlCommand.Parameters.Add("@mBTN", SqlDbType.Char = 6)
HighSqlCommand.Parameters.Add("@mUID", SqlDbType.Char = 10)

vb converts the output to bit types, i don't know why it does this. try
using the following format:

HighSqlCommand.Parameters.Add("@mBTN", SqlDbType.Char, 6)
HighSqlCommand.Parameters.Add("@mUID", SqlDbType.Char, 10)
hth,

diego

Mar 14 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mamun | last post by:
Hi All, I have a stored procedure. I need to create a scheduled job using that stored procedure. I went to Enterprise Manager -->Management--> Jobs-->New Job Properties
6
by: fumanchu | last post by:
I've got to let end users (really just one person) load billing batch files into a third party app table. They need to specify the billing cycle name, the batch name, and the input file name and...
2
by: mike | last post by:
H There are two ways to execute a stored procedure using ADO.NE - call "exec sp_myproc val1,val2" statement over SqlCommand myCommand = new SqlCommand(SQLQuery, mySqlConnection) - use...
2
by: honcho | last post by:
Hello, Does anyone have an example of an SQL Server stored procedure that updates a record, where one of its field is of type "text"? My procedure is /* ** Update the client note and...
4
by: Mr Not So Know It All | last post by:
im new to SQL Server and ASP.Net. Here's my problem. I have this SQL Server stored procedure with an input parameter and output parameter CREATE PROCEDURE . @in_rc varchar(8) @out_eList...
0
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a...
0
by: istruttorenuoto | last post by:
hi! I have some problems to call a stored procedure from an Unix Script. Here's the script stty istrip stty erase ^H export ORACLE_BASE=/product/oracle export...
2
by: Nexstar | last post by:
What is the fastest way to access the database for performance point of view? Should a .Net application call a stored procedure directly or should a .Net application call a web service, or use WCF,...
12
by: barmatt80 | last post by:
I don't know if this is the right part of the forum. But.... I have been working all night trying to create a web service to call a stored procedure in sql server 2008. The stored procedure calls...
5
by: kaushal30 | last post by:
I am getting this error when I call a stored procedure from my C# code. It is a simple stored procedure with six params that inserts data : PROCEDURE LHD_SUR_ADMNEXP_HDR_INS ( ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.