I made this update to update a column in my company table, my column in the database is of type bytea
and I am saving an image as a byte [] ... in my company class, I have the variable is of type Byte [] Foto
public int Update(clsEmpresa E)
{
int r = 0;
string sql = @"update empresa set emp_figura = ?;";
string connString = String.Format("Server={0};Port={1};User Id={2};Password={3};Database={4};",
clsConfigBanco.SERVERNAME, clsConfigBanco.PORT, clsConfigBanco.USERNAME, clsConfigBanco.PASSWORD, clsConfigBanco.DATABASENAME);
using (NpgsqlConnection conexao = new NpgsqlConnection(connString))
{
conexao.Open();
using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao))
{
NpgsqlParameter param = new NpgsqlParameter("emp_figura",
NpgsqlTypes.NpgsqlDbType.Bytea);
param.Value = (E.Foto == null ? null : (E.Foto.Length == 0 ? null : E.Foto));
cmd.Parameters.Add(param);
r = cmd.ExecuteNonQuery();
}
conexao.Close();
}
return r;
}
When I run this method the following error occurs
ERROR: 42601: syntax error at or near ";"
when I do cmd.ExecuteNonQuery;
Would the error be referring to using NpgsqlTypes.NpgsqlDbType.Bytea
related to the type of my parameter? What would be the correct way to save this byte array in the database?