C# - LINQ ERROR "The data type text and varchar are incompatible with Equal Operator"

Asked

Viewed 111 times

1

I find the following error when trying to update a table:

the data type text and varchar are incompatible with Equal Operator.

I have done several searches and most indicate the same solution: change the field to varchar(max). Problem: the field is already varchar(30) and does not even refer to a field of the type Text

Follows the code of update:

public void updateAcaoEstado(string _stp, string _estado)
    {
        try
        {
            bo updtreg = (from bo in db.bos where (bo.bostamp == _stp && bo.ndos == 70) select bo).Single();
            updtreg.cxusername = _estado;
            updtreg.dtclose = DateTime.Today;
            this.db.SubmitChanges();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

Explanation of the fields:

  1. bo.bostamp -> Primary key - char(25)
  2. dtclose -> datetime
  3. cxusername -> varchar(30)

They’re all well-mapped in the file. Some help?

[UPDATE]

Follow the field mapping image cxusername

Mapeamento do campo

[UPDATE 2]

Query extracted from profiler

exec sp_executesql N'UPDATE [dbo].[bo] SET [dtclose] = @p36, [cxusername] = @p37 WHERE ([obrano] = @p0) AND ([boano] = @p1) AND ([ndos] = @p2) AND ([bostamp] = @p3) AND ([nmdos] = @p4) AND ([dataobra] = @p5) AND ([nome] = @p6) AND ([etotaldeb] = @p7) AND ([estab] = @p8) AND ([no] = @p9) AND ([obranome] = @p10) AND ([dataopen] = @p11) AND (NOT ([fechada] = 1)) AND ([dtclose] = @p12) AND ([site] = @p13) AND ([datafecho] = @p14) AND ([datafinal] = @p15) AND ([tabela1] = @p16) AND ([trab2] = @p17) AND ([trab1] = @p18) AND ([series] = @p19) AND ([series2] = @p20) AND ([trab4] = @p21) AND ([quarto] = @p22) AND ([trab3] = @p23) AND ([obs] = @p24) AND ([ousrinis] = @p25) AND ([ousrdata] = @p26) AND ([ousrhora] = @p27) AND ([usrinis] = @p28) AND ([usrdata] = @p29) AND ([usrhora] = @p30) AND ([cxusername] = @p31) AND ([ultfact] = @p32) AND ([vendedor] = @p33) AND ([vendnm] = @p34) AND ([segmento] = @p35)',N'@p0 decimal(10,0), @p1 decimal(4,0),@p2 decimal(3,0),@p3 char(25),@p4 varchar(8000),@p5 datetime,@p6 char(55),@p7 decimal(19,6),@p8 decimal(3,0),@p9 decimal(10,0),@p10 varchar(8000), @p11 datetime,@p12 datetime,@p13 varchar(8000),@p14 datetime,@p15 datetime,@p16 varchar(8000),@p17 varchar(8000),@p18 varchar(8000),@p19 varchar(8000),@p20 varchar(8000),@p21 varchar(8000),@p22 varchar(8000),@p23 varchar(8000),@p24 varchar(8000),@p25 varchar(8000),@p26 datetime,@p27 varchar(8000),@p28 varchar(8000),@p29 datetime,@p30 varchar(8000),@p31 varchar(8000),@p32 datetime,@p33 decimal(4,0),@p34 varchar(8000),@p35 varchar(8000),@p36 datetime,@p37 varchar(8000)', @p0=6,@p1=2019,@p2=70,@p3='882a1f84-fbec-40e1-be9c-5',@p4='00-Acções CRM',@p5='2019-10-22 00:00:00',@p6='3ELEVEN LIMITED',@p7=0,@p8=0,@p9=499,@p10='',@p11='2019-10-28 00:00:00',@p12='1900-01-01 00:00:00',@p13='1834',@p14='1900-01-01 00:00:00',@p15='2019-10-30 00:00:00',@p16='Reunião',@p17='Prospecção',@p18='sdffsd',@p19='sdffsddfs',@p20='sdfsdfsdf',@p21='Roriz não tem interesse no cliente',@p22='Cliente',@p23='',@p24='',@p25='ADM',@p26='2019-10-22 00:00:00',@p27='',@p28='ADM',@p29='2019-10-22 00:00:00',@p30='', @p31='Agendada',@p32='2019-10-31 00:00:00',@p33=22,@p34='',@p35='',@p36='2019-10-23 00:00:00', @p37='Realizado'

  • Is the string that is trying to record nocxusername really less than 30 characters? Do you have mapping class also correct? Could you post?

  • The string I’m trying to record is "Accomplished"....

  • Is there any validation in the model?

  • I put the mapping image

  • Place the class to which the cxusername property belongs.

  • Another thing I forgot to mention, I have one insert which works properly, the update is that not

  • What class are you referring to, layout or designer ?

  • Where it is declared public string cxusername { get; set; }

  • The LINQ is what this abstraction is about, I simply do the mapping according to what is in the database.. That is, the attribute cxusername is inserted inside the table bo i just have to call table bo in the file Linq2SQL (name I gave), later creating the classe with the intended methods

  • If necessary, I can put the file code here dbml.

  • @Adrianomaia, have you checked the query that is being generated? Could you ask the question?

  • @Georgewurthmann already put the query extracted from profiler, if useful

  • @Georgewurthmann I have two attributes mapped with varchar(max)

Show 8 more comments

1 answer

2


I finally found the solution in the following question:

reply

The following code was missing in one of the fields defined as varchar(max):

UpdateCheck=UpdateCheck.Never

Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.