Solved

Stored Procedure with NVARCHAR

Posted on 2004-08-22
3
1,438 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

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

786 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