代码之家  ›  专栏  ›  技术社区  ›  Christian Payne Larry Baltz

varchar(max)+linq到sql

  •  4
  • Christian Payne Larry Baltz  · 技术社区  · 14 年前

    similar questions ,但它们在sql端。

    我需要怎么做才能得到整个场地?

    如:

    using (DataContext dc = new DataContext())
    {
        var foo = dc.foos.First();
        if (foo.Formula2.Length > 4000)
        {
            Console.WriteLine("success!");
        }
    }
    

    setting TextSize 但没什么区别

    dc.ExecuteCommand("SET TEXTSIZE 100000;");
    var foo = dc.foos.First();
    

    alt text

    如果我尝试将类型更改为其他类型(如Object),则会收到消息' '

    有什么建议吗?

    2 回复  |  直到 7 年前
        1
  •  3
  •   Community CDub    7 年前

    thanks 888 .

    这似乎有点复杂,但它的工作。

    将字段转换为数组,然后再转换回字符串。

    var foo = dc.foos.First();
    string formula = new string(foo.Formula2.ToArray());
    
        2
  •  2
  •   Bonshington    14 年前

    听起来像.net将varchar转换为nvarchar 试试这个

    //1 set col in db to varbinary(max)
    
    //2 and when u want to save to db
    string formula = "...";
    System.Data.Linq.Binary bin = new System.Data.Linq.Binary(System.Text.Encoding.ASCII.GetBytes());
    
    //3 when u pull ou
        Binary bin = row.Formula2;
        string formula = System.Text.Encoding.ASCII.GetString(bin.ToArray());