2017-01-23 113 views
0
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参数添加到上面的查询,但它没有添加任何人都可以帮我解决这个问题吗?在c#中的Oracle参数化查询

+0

我看到的第一件事情是,新的登录参数永远不会被分配'ParameterDirection'。 – CDove

+0

[踢坏的习惯:使用旧式JOIN](http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/bad-habits-to-kick-using-old-style-joins。 aspx) - 在ANSI - ** 92 ** SQL标准(** 25年**之前)中将旧式*逗号分隔的表*样式列表替换为* proper * ANSI'JOIN'语法不鼓励使用 –

回答

2

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

谢谢你对我有用。 –

+0

很高兴听到它。如果这是修复,请不要忘记接受答案。 – chadnt