Home » VB.NetRSS

sql server / C# and ntext data,,,,,

Hello to every one!!

What I want to do is to execute an SqlCommand with C# which will insert a big text in a column of a table of my database which type is ntext!!

 

e.g.:

string com = "insert table (column) values('" + text + "')";

SqlCommand mySqlCommand_new;

mySqlCommand_new = SQLConnection.CreateCommand();

mySqlCommand_new.CommandText = com;

mySqlCommand_new.ExecuteNonQuery();

 

It works but it seems to cut my 'text'!! I used datalength function and it gave the number "16000"!! how can I overcome this limit for my "insert" command?? any idea would by very useful!! Sorry if there are mistakes:$ and thanks in advance!!!!!!

 

6 Answers Found

 

Answer 1

ntext datatype deprecatred in next version..

Change that data  type to nvarchar(max)

 

Answer 2

sorry but what "deprecatred" means:$?

I'm using Sql server  2000 and I think that there is not nvarchar(max) data  type.......

 

Answer 3

deprecated means removed in future version... 

any way, as u r using sql2000, u can't user varchar(max) .

In sql  2000, u can't use the local variables of size more than 8000. Probably it is affecting... can you try to create a procedure and execute that proc by passing paramter.

create proc insertdata 
(
 @longtext text
)
as
begin
   insert into Tablename values (@longtext)
   
end
 

Answer 4

What is the length of the data  that you are inserting in the text column? I think the limit is 2,147,483,647 characters according to books.

You might be experiencing this issue when you are selecting the ntext  column. The number of characters in the result column of SELECT statement are limited. You can check it in options of your query analyzer.

ntext, text, and image data types will be removed in a future version of MicrosoftSQL Server

 

Answer 5

What is the length of the data  that you are inserting in the text column? I think the limit is 2,147,483,647 characters according to books.

You might be experiencing this issue when you are selecting the ntext  column. The number of characters in the result column of SELECT statement are limited. You can check it in options of your query analyzer.

ntext, text, and image data types will be removed in a future version of MicrosoftSQL Server

I know that "The number of characters in the result column of SELECT statement are limited." In Sql Server 2000 it can select only 255 characters I think..... I think that I managed it!! I changed the statement....:

 

e.g.:

SqlCommand mySqlCommand_new;

mySqlCommand_new = SQLConnection.CreateCommand();

mySqlCommand_new.CommandText = "insert table (column) values(@text)";

mySqlCommand_new.Parameters.Add(new SqlParameter("@text", SqlDbType.NText));

mySqlCommand_new.Parameters["@code"].Value = text;

mySqlCommand_new.ExecuteNonQuery();

 

where text is my big text!!! Thanks for your replies!!

 

Answer 6

Hi dracy,

try this~~~

string text = "[your text here]";
string com = "insert table (column) values(@text)";

SqlCommand mySqlCommand_new = SQLConnection.CreateCommand();
mySqlCommand_new.CommandText = com;
mySqlCommand_new.Parameters.Add(new SqlParameter("@text", SqlDbType.NText)).Value = text;

mySqlCommand_new.ExecuteNonQuery();


????????
 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter