Oracle Parameterized query in c#

佐手、 提交于 2019-12-12 15:13:48

问题


string sqlCmd = @"SELECT r.row_id AS resp_id,
                         r.name AS resp_name
                  FROM srb.s_resp r,
                       srb.s_per_resp pr,
                       srb.s_contact c,
                       srb.s_user u
                  WHERE r.row_id = pr.resp_id
                    AND u.row_id = c.row_id
                    AND c.person_uid = pr.per_id
                    AND UPPER(u.login) = @login
                 ORDER BY r.name";

OracleConnection con = new OracleConnection(getConnectionString(username, password));
OracleCommand command = con.CreateCommand();

conSiebel.Open();
command.CommandType = CommandType.Text;
command.Connection = con;
command.CommandText = sqlCmd;

command.Parameters.Add(new OracleParameter("login", username));

IDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
reader.Close();

I am trying to add the @login parameter to the above query but it was not adding, Can anyone help me to fix this ?


回答1:


Use a colon instead (:login).

 string sqlCmd = @"SELECT  r.row_id AS resp_id,
                                    r.name AS resp_name
                            FROM    srb.s_resp r,
                                    srb.s_per_resp pr,
                                    srb.s_contact c,
                                    srb.s_user u
                            WHERE   r.row_id = pr.resp_id
                                    AND u.row_id = c.row_id
                                    AND c.person_uid = pr.per_id
                                    AND UPPER(u.login) = :login
                                    ORDER BY r.name";


来源:https://stackoverflow.com/questions/41811897/oracle-parameterized-query-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!