Solved

Stored Procedure with NVARCHAR

Posted on 2004-08-22
3
1,434 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:mayankeagle
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:mayankeagle
ID: 11867462
Thanks. That's what happens when you mix up one DB's syntax with the other.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

708 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

13 Experts available now in Live!

Get 1:1 Help Now