Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: SQl error - Syntax error converting the nvarchar value ....

  1. #1
    Join Date
    Mar 2005
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default SQl error - Syntax error converting the nvarchar value ....

    Error:
    Syntax error converting the nvarchar value 'Jaimal Chohan' to a column of data type int.
    SQL Stored Proc:
    CREATE PROCEDURE proc_get_full_name
    (
    @user_id bigint
    )
    AS
    Declare @forename nVarChar(50)
    Declare @surname nVarChar(50)
    Declare @fullname nVarChar(101)

    SELECT @forename = forename, @surname = surname FROM tbl_users WHERE user_id = @user_id

    SET @fullname = @forename + ' ' + @surname

    RETURN @fullname
    asp.net/vb.net Code
    conGetName = New SqlConnection(ConfigurationManager.AppSettings("co nnectionString"))

    cmdGetName = New SqlCommand("proc_get_full_name", conGetName)
    cmdGetName.CommandType = CommandType.StoredProcedure
    cmdGetName.Parameters.Add("@user_id", user_id)

    paramReturnvalue = cmdGetName.Parameters.Add("RETURN_VALUE", SqlDbType.nvarchar)
    paramReturnvalue.Direction = ParameterDirection.ReturnValue

    conGetName.Open()
    cmdGetName.ExecuteNonQuery()
    fullname = cmdGetName.Parameters("RETURN_VALUE").Value
    conGetName.Close()

    Response.Write(fullname)
    Hmm, I am really confused as to this, even trying to just return @forename returns the same error. Its a pretty simple stored proc, hmmm.

  2. #2
    Join Date
    Feb 2004
    Posts
    4,901
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    Try usng a CAST or CONVERT on:

    SET @fullname = @forename + ' ' + @surname
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

  3. #3
    Join Date
    Mar 2005
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well, I tried it like this

    SET @fullname = CAST(@forename As nVarChar(50)) + CAST(' ' AS nVarChar(1)) + CAST(@surname AS nvarchar(50))
    never had to use CAST or CONVERT before

    anyway, it didn;t work, still returning the exact same error

    Also tried

    RETURN CAST(@forename + ' ' + @surname AS nVarchar(101))

    with the same error being returned.

    Line 59: conGetName.Open()
    Line 60: cmdGetName.ExecuteNonQuery()
    Line 61: fullname = cmdGetName.Parameters("RETURN_VALUE").Value
    Line 62: conGetName.Close()

    Ill probably have to get rid of the storedProc becuase its stopping development

  4. #4
    Join Date
    Feb 2004
    Posts
    4,901
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    I think it has something to do with the SPROC not knowing what type of data it will be returning...

    What you are doing would be more suited inside a User Defined Function...
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

  5. #5
    Join Date
    Mar 2005
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Warren Ashcroft
    I think it has something to do with the SPROC not knowing what type of data it will be returning...

    What you are doing would be more suited inside a User Defined Function...
    LOL, I can;t belive that I am such an idiot

    Rule #1 - look in a book, I didn't

    Anyway, thanks to asp.net Unleashed by Sams (which I most definalty going to call the only guide to asp.net worth buying) I found out the Return only returns an Integer type, and also that I learned how to use Output parameters correctly (which I tried sometime last week, unsucessfully, following a 'guide' on the net)

    Thanks for the help Warren!

  6. #6
    Join Date
    Jun 2005
    Posts
    1,081
    Thanks
    4
    Thanked 15 Times in 15 Posts

    Default

    It's a shame I just read this, as I spotted that mistake. Anyway, I guess you are ok now that you

  7. #7
    Join Date
    Mar 2005
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Sol
    It's a shame I just read this, as I spotted that mistake. Anyway, I guess you are ok now that you
    Hehe, well you only learn though mistakes

  8. #8
    Join Date
    Feb 2004
    Posts
    4,901
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    No problem
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

  9. #9
    Join Date
    Sep 2005
    Posts
    190
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Out of my league, not having been a .net user but one thing I remain glad of was the first computer lanuguage that made any sense at all to me (unless spaghetti on line number basic) was Borland's Turbo Pascal. It was quite strict with data types so that was one thing I think I learned. I remain an amatuer/hobbiest/try my best but think it forced me into learning some things.

  10. #10
    Join Date
    Mar 2005
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Jon Freeman
    Out of my league, not having been a .net user but one thing I remain glad of was the first computer lanuguage that made any sense at all to me (unless spaghetti on line number basic) was Borland's Turbo Pascal. It was quite strict with data types so that was one thing I think I learned. I remain an amatuer/hobbiest/try my best but think it forced me into learning some things.
    I was pretty good with Pascal, back in 2000 did my A'Level project as a payroll system, but then I went to Uni. They tried to teach me Java based OOP using some pathetic program called BlueJ, I just got bored with it (and the rest of Uni for that matter, I mean c'mon who really needs to know about probablity, linear algrbra, Chernobyl happened, how to describe a diamond etc etc etc). So I quite Uni (after getting a HND) and started to Teach My Self

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. MySQL Error where all was well before?
    By Wise Webs in forum MySQL
    Replies: 2
    Last Post: 21st May 2006, 10:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •