Solved

Can't pass ntext getting conversion error

Posted on 2008-10-02
3
800 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change Format on Data when exporting to Excel 4 32
Error on link 14 46
Moving code from one TFS branch to another 3 25
Sending receiving text messages in vb.net 15 33
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…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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