LINQ to SQL更新(C#) [英] LINQ to SQL Update (C#)

查看:75
本文介绍了LINQ to SQL更新(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我表的脚本:

CREATE TABLE ClientTypes
(
    type_id int PRIMARY KEY IDENTITY,
    type_name varchar(250) not null,
    type_applications_list text,
    dtIntro datetime DEFAULT(getdate())
)


在ASP.net中,我正在尝试这样做:


And in ASP.net i'm trying to do this:

protected void btnActualizar_Click(object sender, EventArgs e)
    {
        var aplicacao = (from apl in dc.ClientTypes
                         where apl.type_id == tipoCliente
                         select apl).Single();

        aplicacao.type_name = txtAplicações.Text.ToString();

        dc.SubmitChanges();
    }

但是,当它运行时,它崩溃并说:

However, when it runs, it crashes and says:

文本类型和varchar的数据类型在等于运算符中不兼容."

"The data types text and varchar are incompatible in the equal to operator."

我真的不想将SQL数据类型更改为varchar,我希望它保留在文本中. 我已经使用其他数据类型值(例如int)进行了一些测试,一切顺利.

I really don't want to change the SQL Datatype to varchar, i would like it to stay in text. I have made some tests, with other datatype values, like int... and everything went well.

我真的不明白这一点,因为我在使用返回字符串的控件.

I really don't understand this, has im using a control which returns a String.

提前谢谢

有人可以帮助我吗? 提前谢谢.

Can anyone help me? Thx in advance.

推荐答案

MSDN状态您不应该使用文本数据类型,因为它将在将来的SQL Server版本中删除.文本数据类型无法比较或排序,因此,如果要在LINQ查询中进行比较,则必须更改类型.

MSDN states that you should not use the text data type as it will be removed in future versions of SQL Server. The text data type cannot be compared or sorted so if you want to compare in your LINQ query, you'll have to change the type.

这篇关于LINQ to SQL更新(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆