2

I am developing a Library Management System using Visual Studio 2015 as a front end and Microsoft SQL Server 2014 as back-end to store data.

This is my table design:

enter image description here

But when I try to pass data from Visual Studio, it saves as blank spaces to the defined length.

enter image description here

For example if store a text contain 10 characters on title remaining 490 store as blank space.

The highlighted are the blank space in the column. If I set the length 10 which is default I cannot store data more than 10

Is there any solution for this? is this a issue on my database or Visual Studio?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
NaFi
  • 81
  • 1
  • 13
  • Possible duplicate of [What is the difference between char, nchar, varchar, and nvarchar in SQL Server?](http://stackoverflow.com/questions/176514/what-is-the-difference-between-char-nchar-varchar-and-nvarchar-in-sql-server) – James Z Jan 07 '17 at 22:32

2 Answers2

7

You're using the wrong data type. nchar is fixed length. You need to use nvarchar (variable length).

benjrb
  • 766
  • 1
  • 5
  • 13
4

Read this before using the datatypes you are using. instead of nchar you should use nvarchar

nchar [ ( n ) ]

Fixed-length Unicode string data. n defines the string length and must be a value from 1 through 4,000. The storage size is two times n bytes. When the collation code page uses double-byte characters, the storage size is still n bytes. Depending on the string, the storage size of n bytes can be less than the value specified for n. The ISO synonyms for nchar are national char and national character..

nvarchar [ ( n | max ) ]

Variable-length Unicode string data. n defines the string length and can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size, in bytes, is two times the actual length of data entered + 2 bytes. The ISO synonyms for nvarchar are national char varying and national character varying.

for more about DataTypes Read

Community
  • 1
  • 1
Meer
  • 2,765
  • 2
  • 19
  • 28