Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2003
    Posts
    1

    Question Unanswered: How to call a stored procedure in AS/400 from C#

    Please, anyboy how to call a stored procedure in AS/400 from C#??

    I tried this:

    /////////////////////////////////////////////////////
    OleDbConnection conexionBD=new OleDbConnection();
    conexionBD.ConnectionString=strConnection;
    conexionBD.Open();

    OleDbCommand command=new OleDbCommand();
    command.Connection=conexionBD;
    command.CommandText="CALL RECPGM.PRUEBAR(?)";

    //Param
    command.Parameters.Add("@TIPO", System.Data.OleDb.OleDbType.Char).Value = "A";
    command.Parameters["@TIPO"].Size = 1;
    command.Parameters["@TIPO"].Direction = ParameterDirection.InputOutput;

    command.Prepare();

    int kk;
    kk=command.ExecuteNonQuery();

    Response.Write("--> " + command.Parameters["@TIPO"].Value.ToString() + " <br>");

    conexionBD.Close();
    ////////////////////////////////////////////////

    And i get the error SQL7985, any idea????

    Thank you.

  2. #2
    Join Date
    Sep 2003
    Posts
    1
    hello

    I assume you may have found an answer by now. But just in case. I've recently been jumping through similar hoops!

    By default the CommandType on the command is CommandType.Text and in which case you have to set the CommandText to the SQL that you wish to run e.g. in your example

    command.CommandText="CALL RECPGM.PRUEBAR(?)";

    Instead, set the
    command.CommandType = CommandType.StoredProcedure

    in this case the commandtext should merely be the NAME of the stored procedure that you wish to call.

    command.CommandText = "RECPGM.PRUEBAR";
    You do not need to specify the call, nor the parameter markers. The parameters merely have to be added to the command.

    For full help text, look at the VS help under
    .Net Framework
    Reference
    Class Library
    System.Data.OleDb
    OldDbCommandClass
    Properties
    CommandTypeProperty

    On the help for the CommandTypeProperty you will also see a link to 'using stored procedures with a command' which gives some useful examples.

    Using CommandType of StoredProcedure you do not get the SQL7985 exception thrown.

Posting Permissions

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