2

I run these commands in a Windows Forms app written in C#:

NpgsqlCommand command = new NpgsqlCommand("DO $$ BEGIN IF EXISTS(select id from clients where id=@cnumberclient) THEN INSERT INTO reservations(roomnumber,clientnumber,datein, dateout) values(@rnumber, @cnumber, @din, @dout); ELSE raise notice 'HYI'; END IF; END $$;", conn.getConnection());
command.Parameters.Add("@cnumber", NpgsqlDbType.Integer).Value = ClientId;
command.Parameters.Add("@cnumberclient", NpgsqlDbType.Integer).Value = ClientId;
command.Parameters.Add("@rnumber", NpgsqlDbType.Integer).Value = RoomId;
command.Parameters.Add("@din", NpgsqlDbType.Date).Value = dateIn;
command.Parameters.Add("@dout", NpgsqlDbType.Date).Value = dateOut;

then I open the connection and execute the command:

conn.openConnection();

if (command.ExecuteNonQuery() == 1)

But I get an error.

column "cnumberclient" doesn't exist

Postgres doesn't seem to see the parameters Can you help me?

1
  • 1
    Possibly relevant npgsql.org/doc/… Maybe put spaces around it, as npgsql has to parse and replace named parameters with positional parameters before sending the query Commented Jun 8, 2022 at 19:46

1 Answer 1

5

Remove the @ symbol from your parameters, that's not part of the parameter name, it's the symbol to identify them in the Sql query.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.