Solved

Can't pass ntext getting conversion error

Posted on 2008-10-02
3
799 Views
Last Modified: 2013-11-07
I'm using a DataAdapter and am trying to pass through a parameter which is accepted as ntext by the stored procedure

The value I have in the page is a string, which I know is converted to an ntext in C# when it exceeds the 4000 limit. In this case that will happen

adding paramter as such

da.SelectCommand.Parameters.Add("@purchases", SqlDbType.NText);
da.SelectCommand.Parameters["@purchases"].Value = purchases;

When it gets to a value for "purchases" that has been converted to ntext I get the following error:

SqlException: Implicit conversion from data type ntext to varchar is not allowed. Use the CONVERT function to run this query

But I'm explicitly trying to pass it as ntext as the sqldbtype, right? How do I convert this string variable "purchases" into the appropriate value

thanks in advance
0
Comment
Question by:animated405
  • 2
3 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 22629634
change your select command from:
    SELECT * FROM YOURTABLE WHERE YourNTextField = @purchases
To:
    SELECT * FROM YOURTABLE WHERE YourNTextField = CONVERT(NTEXT, @purchases)

then you ca use:

da.SelectCommand.Parameters.Add("@purchases", SqlDbType.Varchar);
da.SelectCommand.Parameters["@purchases"].Value = purchases;
0
 

Author Comment

by:animated405
ID: 22688111
yeah tried it but it didn't work, which I don't get. I need to step through the code just got busy on other stuff right after I wrote this. I will check it out soon and provide a response. Not trying to chince out...
0
 

Author Comment

by:animated405
ID: 22745518
i am apparently never going to get back to this. thanks again
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

22 Experts available now in Live!

Get 1:1 Help Now