February 24, 2015 at 9:21 am
Need help, I am looking for Sql Server DATALENGTH() alternative or equivalent function in C#, that gives me string storage for SQL CLR
February 24, 2015 at 9:26 am
inside the CLR, if you are using a datatable to hold the data, you can find the max length of the values in the a column, , or if you stuff a single value into a string variable, MyVariable.Length() has that value as well.
what are you looking for specifically?
Lowell
February 24, 2015 at 9:30 am
Thanks for the reply,
I have already considered c# "str".length properties as DATALENTGH('str') of SQL Server , but is not giving me similar result, c# length gives me 3000 , while DATALENGTH gives me 6000 for same string.
Then I go for System.Text.ASCIIEncoding.ASCII.GetByteCount('str'), it is also same as Length.
I want DATALENTH('largetext......') = C# ??
Thanks
February 24, 2015 at 9:55 am
the datalength of an NVARCHAR is doubled, as that is telling you how much storage is required in SQL;
i don't think that is relevant in c#, is it?
/*--Results
(No column name)(No column name)(No column name)(No column name)
3633
*/
select
datalength('abc'),
datalength(N'abc'),
len('abc'),
len(N'abc')
you could multiply it by two if you know the datasource is a ntext/nchar/nvarchar data type.
Lowell
February 24, 2015 at 10:00 am
Yes , you are right, I want tweak that C# would return exact DATALENGTH of string (nvarchar)
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply