gpt4 book ai didi

c# - C# 中的 Oracle 参数化查询

转载 作者:行者123 更新时间:2023-11-30 14:24:14 27 4
gpt4 key购买 nike

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();

我正在尝试将 @login 参数添加到上述查询中,但它没有添加,任何人都可以帮我解决这个问题吗?

最佳答案

改用冒号 (: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";

关于c# - C# 中的 Oracle 参数化查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41811897/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com