c# - MySQL Insert & Select in same statement returns 'records' when none exist -


so have following code (heavily simplified) -

mysqlcommand cmd = new mysqlcommand(@"insert helpdesk.calls set callid = @callid, viewed = 1, date = current_timestamp(); select * helpdesk.calls id = @callid", con); cmd.parameters.add("callid", mysqldbtype.int32).value = id; using (mysqldatareader reader = cmd.executereader()) {     if (reader.read()) {         retval = tocallheader(reader);     } else {         // never throws reader.read() returns true.         throw new exception(string.format("call ({0}) not found", id));     } } 

where inserting record , running select @ same time. problem reader.read() returns true whether rows selected select statement or not when insert statement used. behavor design , require 2 queries transaction?

that insert query syntax wrong , throw exception.

insert helpdesk.calls set callid = @callid, viewed = 1, date = current_timestamp(); 

check here correct sql syntax on insert statement: https://www.w3schools.com/sql/sql_insert.asp


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -