Solved

Stored Procedure with NVARCHAR

Posted on 2004-08-22
3
1,436 Views
Last Modified: 2012-06-27
Hi,

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.

Thanks,
Mayank.
0
Comment
Question by:Mayank S
3 Comments
 
LVL 12

Accepted Solution

by:
kselvia earned 30 total points
ID: 11863236
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)
0
 
LVL 4

Assisted Solution

by:hamood
hamood earned 20 total points
ID: 11863254
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

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

look at this statement

@GroupName varchar(100)

i think you have missed the length here.

Hamood
0
 
LVL 30

Author Comment

by:Mayank S
ID: 11867462
Thanks. That's what happens when you mix up one DB's syntax with the other.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now