0

I am trying to use bind variables in C# to get records in select query. The below code is what I've tried but I get exception as: ORA-01006: bind variable does not exist . I'm not getting where is the variable being not present or something else ?

string sleeveListQuery = @"select col from table where id = :V1  :V2 ";
    
                    inClause="some condition";                
                    List<SleeveSearch> sleeveSearchList= new List<SleeveSearch>();
                    using (OracleConnection objConn = new OracleConnection(ConnectionString))
                    {
                        objConn.Open();
                        using (var command = objConn.CreateCommand())
                        {
                            command.CommandText = sleeveListQuery;
                            command.Parameters.Add(":V1", OracleDbType.Int32, Int32.Parse(univId), ParameterDirection.Input);
                            command.Parameters.Add(":V2", OracleDbType.Varchar2, inClause, ParameterDirection.Input);
                            OracleDataReader dr = command.ExecuteReader();
                            while (dr.Read())
                            {
                                SleeveSearch dataRow = new SleeveSearch();
                                dataRow.SleeveName = dr["SLEEVENAME"].ToString();
                                sleeveSearchList.Add(dataRow);
                            }
                        }
                        
                    }
Shalini Raj
  • 177
  • 2
  • 19

1 Answers1

0

You are adding the parameters to the command, but you are not supplying any Value for them. ie:

//...
command.Parameters[":V1"].Value = 10;
command.Parameters[":V2"].Value = "Hello";
//...

PS: Probably you meant:

... where id = :V1 and something = :V2
Cetin Basoz
  • 22,495
  • 3
  • 31
  • 39
  • command.Parameters.Add(":V1", OracleDbType.Int32, Int32.Parse(univId), ParameterDirection.Input); doesnt this adds value ? i assumed this did – Shalini Raj Jun 14 '21 at 12:29
  • @ShaliniRaj, Oh I see you have the value parameter also. I missed that. I prefer the style Parameters.Add(parameterName, parameterType).Value = ... But anyway, your syntax were wrong too. – Cetin Basoz Jun 14 '21 at 13:26