nvarchar(max) sql data type equivalen in c#

S

skg

i am writing a UDF which takes nvarchar(max) as input parameter. Can any one
tell me what is the equivalent of this data type in C#.
Thx
 
M

Marina Levit [MVP]

There isn't one. You can have a 'string', but you wouldn't be able to
specify a maximum length to it, and you wouldn't need to specify that it can
hold unicode data.
 
S

skg

Thanks Marina !!! I posted this in public.SQLServer.programming newsgroup
today, sorry, don't know how to copy the link to that thread for you.
But here is what i am seeing when i do return Length of the input string i
get 4000 always. i am concerned i am loosing bytes when calling the UDF.
Using SQLChar i get correct size. Here is my code snippet. i am i doing
something wrong.


using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Collections;
using System.Security.Cryptography;
using System.Text;

public partial class UserDefinedFunctions
{

[SqlFunction(IsDeterministic = true, IsPrecise = true, DataAccess =
DataAccessKind.None)]
public static SqlInt32 GetLength(string sInputString)
{
return (SqlInt32)sInputString.Length;
}
};


select top 10
id,datalength(blobfield)[SQLSize],dbo.GetLength(blobfield)[UDFSize] from
Table1 where datalength(blobfield) > 8000


id SQLSize UDFSize
----------- -------------------- -----------
2 49874 4000
13 28860 4000
62868 8166 4000
62873 9702 4000
62874 36546 4000
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top