How to pass a unicode character as parameter for a store procedure in vb.net

Ranjith Jain 11 Reputation points
2022-06-15T10:19:38.713+00:00

0

i am trying to pass a list of ids as a parameter of a stored procedure from vb.net. And these IDs can have unicode characters as well.

EXEC sp_IMS_RP_GetItemDetail @ItemID = '''736'', ''φ736'''

i am aware that if the parameter is defined as nvarchar it will go through. but once the parameter value gets into the stored procedure the unicode character gets converted and it wont go through for further querying. i was able to find out and tested as well that if i pass the parameter value by appending a N character before the value, the unicode character doesnt get converted.

EXEC sp_IMS_RP_GetItemDetail @ItemID = N'''736'', ''φ736'''

But i am failing to find a way to append a N character programmatically from vb.net.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,599 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,559 questions
{count} votes

11 answers

Sort by: Most helpful
  1. Naomi 7,361 Reputation points
    2022-06-17T14:27:51.24+00:00

    I didn't look into your procedure code, but you can use STRING_SPLIT function to separate your list of items into a table. What you posted as the beginning of the SP is already not written correctly. Even if you would need to resort to dynamic SQL, you need to use it properly. The SQL variable needs to be declared as nvarchar(max). But most likely you don't need dynamic SQL in your procedure even if number of parameters is big and you're passing comma-delimited list of items.