Returning value from Like statement in SQL server 2008 to vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chuckzter
    New Member
    • Oct 2007
    • 56

    Returning value from Like statement in SQL server 2008 to vb.net

    I'm in a bit of a pickle here. I need to pass the variable @uname which gets a value from a text box to a statement on one of my stored procedures in SQL server and return an output on my form.

    Here is the code:

    in .net
    Code:
    cmd = New SqlCommand
            cmd.CommandText = "sp_TransData"
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Parameters.Add("@unamex",SqlDbType.VarChar,15)
            cmd.Parameters.Add("@Username",SqlDbType.VarChar, 15)
            cmd.Parameters("@unamex").Value = txt_User.Text
            cmd.Parameters("@Username").Direction = ParameterDirection.Output
    
            Call startCon()
            cmd.Connection = conData
            cmd.ExecuteNonQuery()
     tempvalue(0) =(cmd.Parameters("@Username").Value.ToString)
    
    MsgBox("" + tempvalue(0))
    on my stored proc
    Code:
    ALTER PROCEDURE [dbo].[sp_TransData] 
    @unamex varchar(15), @Username varchar(15) output
    
    AS
    set nocount on;
    
    BEGIN
    
    sets from
    	
    Select  @Username = Username from tbl_UserPro where Username like @unamex
    
    END
    What happens is that it returns a NULL VALUE. ""

    I've tried a couple of things like, running the "like statement" on SQL server having
    Code:
     SELECT [Username] FROM [dbQuines].[dbo].[tbl_UserPro] WHERE Username like '%a%'
    and it works.

    I'm not really sure what i'm doing wrong here. I need guidance. Thanks in advance.
  • chuckzter
    New Member
    • Oct 2007
    • 56

    #2
    I almost forgot to mention that tbl_UserPro on my stored procedure where i get all my data is not really a table but i created it from "Views" i'm not really sure if that helps, but i'm looking on it.

    Comment

    • chuckzter
      New Member
      • Oct 2007
      • 56

      #3
      I just added this line on my stored proc and it worked wonderfully.

      SELECT @unamex = RTRIM(@unamex) + '%'

      Comment

      Working...