Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Adding Parameter to a Stored Procedure that returns a `LIKE` quey!!

Adding Parameter to a Stored Procedure that returns a `LIKE` quey!!

Scheduled Pinned Locked Moved C#
databasehelpcsharporacle
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Minimech
    wrote on last edited by
    #1

    Hello all, i had no problem at adding parameters to a stored procedure and puttng the result in a dataset until i stated trying this with a Stored Procedure with select * from table where column like something+'% that takes parameters.. The problem is that it says `invalid number` at runtime not when executing procdure at my editor, so the problem is passing the parameters but i couldn`t figure it out, btw i use Oracle; Let me give you the codes of stored procedure and how i call it from c# :

    CREATE OR REPLACE PROCEDURE OGR_USER.studentfind(std_FName nvarchar2, std_LName nvarchar2, pRc out sys_refcursor)
    as
    
    begin
    
    open pRc for select * from ogr_user.STUDENT WHERE FNAME LIKE std_FName+'%' AND  LNAME LIKE std_LName+'%';  
    
    end;
    
    OracleParameter std_FName = new OracleParameter("std_FName", OracleDbType.NVarchar2);
                std_FName.Value = name;
                std_FName.Size = 100;
                comm.Parameters.Add(std_FName);
    
                OracleParameter std_LName = new OracleParameter("std_LName", OracleDbType.NVarchar2);
                std_LName.Value = surname;
                std_LName.Size = 100;
                comm.Parameters.Add(std_LName);
    
                comm.Parameters.Add("pRc", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
    

    i tried parameters type varchar, nvarchar thinking that it would make a difference but no luck, i would really appreciate if anyone could help me with this, something goes wrong when i use like and % because i used the same code without a like query and there was no problem

    P M 2 Replies Last reply
    0
    • M Minimech

      Hello all, i had no problem at adding parameters to a stored procedure and puttng the result in a dataset until i stated trying this with a Stored Procedure with select * from table where column like something+'% that takes parameters.. The problem is that it says `invalid number` at runtime not when executing procdure at my editor, so the problem is passing the parameters but i couldn`t figure it out, btw i use Oracle; Let me give you the codes of stored procedure and how i call it from c# :

      CREATE OR REPLACE PROCEDURE OGR_USER.studentfind(std_FName nvarchar2, std_LName nvarchar2, pRc out sys_refcursor)
      as
      
      begin
      
      open pRc for select * from ogr_user.STUDENT WHERE FNAME LIKE std_FName+'%' AND  LNAME LIKE std_LName+'%';  
      
      end;
      
      OracleParameter std_FName = new OracleParameter("std_FName", OracleDbType.NVarchar2);
                  std_FName.Value = name;
                  std_FName.Size = 100;
                  comm.Parameters.Add(std_FName);
      
                  OracleParameter std_LName = new OracleParameter("std_LName", OracleDbType.NVarchar2);
                  std_LName.Value = surname;
                  std_LName.Size = 100;
                  comm.Parameters.Add(std_LName);
      
                  comm.Parameters.Add("pRc", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
      

      i tried parameters type varchar, nvarchar thinking that it would make a difference but no luck, i would really appreciate if anyone could help me with this, something goes wrong when i use like and % because i used the same code without a like query and there was no problem

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      That's not a procedure; it's just a simple query -- pass it to ExecuteReader. And try adding the percent signs when you set the parameter values: std_LName.Value = surname + '%' ;

      1 Reply Last reply
      0
      • M Minimech

        Hello all, i had no problem at adding parameters to a stored procedure and puttng the result in a dataset until i stated trying this with a Stored Procedure with select * from table where column like something+'% that takes parameters.. The problem is that it says `invalid number` at runtime not when executing procdure at my editor, so the problem is passing the parameters but i couldn`t figure it out, btw i use Oracle; Let me give you the codes of stored procedure and how i call it from c# :

        CREATE OR REPLACE PROCEDURE OGR_USER.studentfind(std_FName nvarchar2, std_LName nvarchar2, pRc out sys_refcursor)
        as
        
        begin
        
        open pRc for select * from ogr_user.STUDENT WHERE FNAME LIKE std_FName+'%' AND  LNAME LIKE std_LName+'%';  
        
        end;
        
        OracleParameter std_FName = new OracleParameter("std_FName", OracleDbType.NVarchar2);
                    std_FName.Value = name;
                    std_FName.Size = 100;
                    comm.Parameters.Add(std_FName);
        
                    OracleParameter std_LName = new OracleParameter("std_LName", OracleDbType.NVarchar2);
                    std_LName.Value = surname;
                    std_LName.Size = 100;
                    comm.Parameters.Add(std_LName);
        
                    comm.Parameters.Add("pRc", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
        

        i tried parameters type varchar, nvarchar thinking that it would make a difference but no luck, i would really appreciate if anyone could help me with this, something goes wrong when i use like and % because i used the same code without a like query and there was no problem

        M Offline
        M Offline
        Minimech
        wrote on last edited by
        #3

        Thanks for your advice, tried adding '%' at the and of the value but still invalid number at run time..it is somewhere in parameter setting and adding that i should add something but still could`t figure it :confused:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups