Thanks for the reply. I tried that, and oddly, have the same problem - no data is being returned from the code, although it is when running the SP manually.
Here is the SP and code
CODE
ALTER PROCEDURE procGetName
@IDS int, @ReturnName nvarchar(75) OUTPUT
AS
DECLARE @FullName nvarchar(75),@Lname nvarchar(50),@Fname nvarchar(50), @PatientIDS int;
SELECT @PatientIDS=PatientIDS, @Fname=Fname, @Lname = Lname FROM tblPatient WHERE PatientIDS = @IDS
IF @FNAME IS NULL
SET @FullName = @Lname
ELSE
SET @FullName = @Lname + ', ' + @Fname
set @ReturnName = @Fullname
RETURN
'And the code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cnn As New SqlConnection()
Dim cmd As New SqlCommand
Dim result
Dim CONNECTION_STRING As String = "Data Source=PMK-DC2;Initial Catalog=PB.1.0_be;Integrated Security=True"
Try
cnn.ConnectionString = CONNECTION_STRING
With cmd
.CommandType = Data.CommandType.StoredProcedure
.CommandText = "procGetname"
.Parameters.AddWithValue("@IDS", 5)
.Parameters.Add("@ReturnName", SqlDbType.NVarChar, 75)
.Parameters(0).Direction = ParameterDirection.Input
.Parameters(1).Direction = ParameterDirection.Output
.Connection = cnn
.Connection.Open()
End With
'frmBook.txtName.Text = cmd.ExecuteScalar.ToString
'NOTHING IS RETURNED HERE - 'RESULT' IS AN EMPTY STRING
result = cmd.ExecuteScalar
Debug.Print(result)
Catch ex As Exception
MsgBox(ex.ToString)
Finally
cmd.Connection.Close()
cmd = Nothing
End Try
End Sub
QUOTE(bflosabre91 @ 22 Jul, 2009 - 05:15 AM)

usually my rule of thumb for sql is that i use store procedures for interactions with vb, and functions are used inside sql only. Try creating a stored procedure(spGetName) and i think that might fix your problem. Because you can see in the vb, it specifically says stored procedure, not a function.