Stored Procedure with NVARCHAR


I have an NVARCHAR field in a table and I'm using a stored procedure (which takes the NVARCHAR value as a parameter) to insert rows into the table. I call the stored procedure from a C# .NET application that uses the Microsoft Application Data block. However, when I run the program, I've noticed that the NVARCHAR field in the table only stores the first character of the String which I pass to it.

Any clue what's wrong? It works fine when I shoot a normal insert query from my application. It doesn't work only when I call the stored procedure.

LVL 30
Mayank SAssociate Director - Product EngineeringAsked:
Who is Participating?
Ken SelviaConnect With a Mentor RetiredCommented:
Nvarchar is unicode (2 byte) characters but still requires a length deffinition. If you don't specify, it only holds 1 character just like CHAR would. You need to define it as Nvarchar(2000) (or whatever, up to 4000)
hamoodConnect With a Mentor Commented:
I think you hav'nt specified the length of the field parameter in the stored procedure or in the code where you are calling the stored procedure.

Here is sample stored proc

@GroupName varchar(100) AS
insert into user_groups ([Description]) values(@GroupName)
select @@Identity

look at this statement

@GroupName varchar(100)

i think you have missed the length here.

Mayank SAssociate Director - Product EngineeringAuthor Commented:
Thanks. That's what happens when you mix up one DB's syntax with the other.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.