Reputation: 81
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:
But when I try to pass data from Visual Studio, it saves as blank spaces to the defined length.
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?
Upvotes: 2
Views: 295
Reputation: 2845
Read this before using the datatypes
you are using. instead of nchar
you should use nvarchar
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..
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
Upvotes: 4
Reputation: 836
You're using the wrong data type. nchar
is fixed length. You need to use nvarchar
(variable length).
Upvotes: 7