Forum Discussion

juliemorris's avatar
juliemorris
Occasional Contributor
3 years ago
Solved

A nvarchar(max) column returns as "(WIDEMEMO)" when queried using an ADOQuery on an SQL database

I am querying an SQL database using an ADOQuery, passing in an SQL query statement and returning a result.

When the query uses a SQL column with a type of nvarchar(max), I get (WIDEMEMO) returned rather than the value from the columns cell. I get the correct result if the column type is int, decimal, or nvarchar(n) - n being a specified number. I have tried to convert this to a string before printing, and writing it to the result variable as various type such as "var resultText = Qry.FieldByName(queryColumnTitle).Text;", var resultText = Qry.FieldByName(queryColumnTitle).Value;", var resultText = Qry.FieldByName(queryColumnTitle).AsString;.

Any other ideas? Thanks

 

Code Example 

//Find the ProductId from the Orders table
var queryColumn = "ProductId";   //looking for this - it is type nvarchar(max)
var orderNum = 100;

var statement = "SELECT LineNumber, ProductId FROM Orders WHERE orderNum = :Param_1;";
//Executes query and returns result - args passed in are statement, column to provide the answer from and the order num as a parameter used in the statement
var expectedProductId = DatabaseQuery(statement, queryColumn, orderNum);

 

//this always returns           (WIDEMEMO)

//If I change the var queryColumn, to show the LineNumber, I get a correct result.

  • Solved it myself.

    Just cast the field in the SQL statement...

    SELECT LineNumber, CAST([ProductId] AS nvarchar(50)) AS ProductId FROM Orders WHERE orderNum = :Param_1;

1 Reply

  • juliemorris's avatar
    juliemorris
    Occasional Contributor

    Solved it myself.

    Just cast the field in the SQL statement...

    SELECT LineNumber, CAST([ProductId] AS nvarchar(50)) AS ProductId FROM Orders WHERE orderNum = :Param_1;