Solved

Can't pass ntext getting conversion error

Posted on 2008-10-02
3
798 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
Comment Utility
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
Comment Utility
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
Comment Utility
i am apparently never going to get back to this. thanks again
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Deserialize JSON array VB.Net problem 3 36
.NET Error 7 41
Hovering effect 9 28
What .NET website keeps me current? 9 28
IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
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…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

12 Experts available now in Live!

Get 1:1 Help Now