Solved

Stored Procedure with NVARCHAR

Posted on 2004-08-22
3
1,451 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

707 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