Solved

Can't pass ntext getting conversion error

Posted on 2008-10-02
3
802 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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