VB.Net Stored Procedures

G

Guest

I'm trying to call a stored procedure from vb.net that's on the sql server. I
would like to have the output on another form or a listbox where I can print
results. I'm not getting any errors, but i'm not getting any output either.
Any help appreciated. Thanks.

'Stored Procedure = COMPARE, Output = comp_out. COL001 is returned 'field
from SP.

Dim myCommand As New SqlCommand
Dim myParameter As SqlParameter

Dim myConnection = New SqlConnection("Integrated Security=SSPI;Packet
Size=4096;Data Source=TEST\MYSQL;Initial Catalog=hutty;Persist Security
Info=False;Workstation ID=TEST")

myCommand.Connection = myConnection
myCommand.CommandText = "COMPARE"
myCommand.CommandType = CommandType.StoredProcedure
myParameter = myCommand.CreateParameter()
myParameter.ParameterName = "@comp_out"
myParameter.Direction = ParameterDirection.Output
myParameter.SqlDbType = SqlDbType.VarChar
myParameter.Size = 50
myCommand.Parameters.Add(myParameter)



myCommand.Connection.Open()
myCommand.ExecuteNonQuery()

Span1.Text =
Convert.ToString((myCommand.Parameters("@comp_out").Value.ToString()))

ListBox1.Items.Add(myCommand.Parameters("@comp_out").Value.ToString)
 
G

Guest

Have you check first that your store procedure itseld is working fine from
server side?
 
G

Guest

Yes... I checked the SP through query analyzer. I did make a modification
after this post. The parameter name "comp_out" I deleted from the SP. It
wasn't needed. This is my SP that I'm trying to get the output in VB:

CREATE PROCEDURE [DBO].[COMPARE]
AS
SELECT MIN(TableName) as TableName, COL001
FROM

(
SELECT '[FILE1]' as TableName, Col001
FROM [FILE1]
UNION ALL
SELECT '[FILE2]' as TableName, Col001
FROM [FILE2]
) tmp
GROUP BY COL001
HAVING COUNT(*) = 1
ORDER BY COL001
GO
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top