Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2003
    Posts
    2

    Unanswered: Select Query with parameters from C# to DB2 is not working???

    Hi friends,
    In our application we are accessing db2 with the select query like this."SELECT * FROM MYTABLE WHERE ID =?" with the parameter given.This throws an exception
    "Unhandled Exception: System.Data.OleDb.OleDbException: No error information available: DB_E_NOCOMMAND(0x80040E0C)."

    If i give the query like "SELECT * FROM MYTABLE WHERE ID =1", IT'S WORKING FINE.

    Can any of u tell me how to solve this

    Million thanks to u for listening my probm

    Regs
    kathir

  2. #2
    Join Date
    Jul 2001
    Posts
    32

    Re: Select Query with parameters from C# to DB2 is not working???

    Hi,
    Use EXECUTE (Dynamic SQL) to execute query. Then you can use parameter marker(?) in your query.

    i.e.,
    SET L_VAR_ID=1;
    SET L_VAR_SELECT='SELECT * FROM MYTABLE WHERE ID=?';
    PREPARE L_VAR_SELECT_SQL FROM L_VAR_SELECT;
    EXECUTE L_VAR_SELECT USING L_VAR_ID;


    I think, this will help you.

    Thanks,
    Thangam

  3. #3
    Join Date
    Feb 2003
    Posts
    2

    Re: Select Query with parameters from C# to DB2 is not working???

    Hi thangam(gold),
    Thanks for ur kind reply.In my C# application i dont know how to use ur code.Can u tell me how to implement it with some sample code in c#.

    Thanks a lot

    Kathir

  4. #4
    Join Date
    Apr 2003
    Posts
    2
    Were you ever able to get this working? I am having the exact same problem, and would love to find someone who has fixed this. Please contact me.

  5. #5
    Join Date
    Jul 2003
    Posts
    1

    Re: Select Query with parameters from C# to DB2 is not working???

    I am not entirely sure if this is the proper solution to your problem, but here goes:

    I am assuming that you want to be able to pass a string or an int, which will be later used in your query, so be sure to define it:

    string MyInput = MyTextBox.Text; //This will look read from your textbox



    You already know how to establish a connection and all of that stuff, however, you need to take a few steps to make SQL use your C# defined field:

    "SELECT * FROM MyTable WHERE id = @MyParam"
    cmd.Parameters.Add ("@MyParam", SqlDbType.VarChar);
    cmd.Parameters["@MyParam"].Value = MyIput;



    This has allowed me to be able to query a database, and I am currently playing around with it to see what all it can do. You may want to look for more information regarding parameters - I think that is where you will find your solution.

    Ciao,
    Garret
    Last edited by Winomonkey; 08-14-03 at 21:30.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •