Problem when doing Table Insert in Postgresql

Asked

Viewed 575 times

2

When I’m gonna make a INSERT:

INSERT INTO categoria (cat_descricao,cat_status) VALUES ('não' ,'1' )

passing some element with accentuation parameter the following error occurs

ERROR: 22021: invalid byte Sequence for encoding "UTF8": 0xe3 0x6f 0x27>

But if I do the instruction SQL on its own SGBD it goes normal without any problem, but when I return this information through a DataTable tbm appears with exchanged values. I am using the PostGres and C#

public int ExecutarSQL(string sSQL)
{
    int iLinhas = 0;
    if (ConectaBanco())
    {
        _comando.CommandText = sSQL;
        iLinhas = _comando.ExecuteNonQuery();
        DesconectaBanco();
    }
    return iLinhas;
}

When performing this function the error occurs in the ExecuteNonQuery, apparently appears to be a UTF error, but the bank accepts then the problem is in the language? what action can be taken to solve this problem?

  • 1

    See: http://stackoverflow.com/questions/4867272/invalid-byte-sequence-encoding-utf8

1 answer

3


Change the encondig for latin1 with the command below:

update pg_database set encoding = pg_char_to_encoding('LATIN1') 
where datname = 'nomedoBanco';
  • I managed to solve the problem using this command, thank you !

Browser other questions tagged

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