Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Mon, 29 Mar 2004 @ 11:09:33 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: Stored Procedures and C#
 
From:   Anomy Anom

<-- Anonymously Posted: Monday, March 29, 2004 03:50 -->

I changed the procedure to help testing:

create procedure testdb.TestProc(IN pIn INTEGER,  OUT pOut INTEGER)
BEGIN

SET pOut = pIn * 2;

END;

But I agree it's a bit weird.

In the end I changed it to a 'reader' query and got the output value that way.

I couldn't get the methods on MSDN to work...

Any good to you?

using System;
using Microsoft.Data.Odbc;
using System.Data;

namespace storedProc2
{
      class Class1
      {
            [STAThread]
            static void Main(string[] args)
            {
                  string myConnection = "DSN=TD_testDB;UID=user;PWD=pass";
                  OdbcConnection myConn = new OdbcConnection(myConnection);

                  string myTestQuery = "call testDB.TestProc(?,?)";

                  OdbcCommand sampleCMD = new OdbcCommand(myTestQuery);
                  sampleCMD.Connection = myConn;

                  OdbcParameter prm = sampleCMD.Parameters.Add("pIn", OdbcType.Int);
                  prm.Value = 34;
                  prm.Direction = ParameterDirection.Input;


Console.WriteLine(sampleCMD.Parameters[0].ParameterName + " = " + sampleCMD.Parameters[0].Value.ToString());

                  try
                  {
                        myConn.Open();
                        Console.WriteLine(sampleCMD.CommandText);
                        OdbcDataReader r = sampleCMD.ExecuteReader();

                        while (r.Read())
                        {
                              int pOut = r.GetInt32(0);
                              System.Console.WriteLine("pOut = " + pOut.ToString());
                        }

                        r.Close();
                        myConn.Close();
                  }

                  catch(Exception e)
                  {
                        Console.WriteLine(e.ToString());
                        Console.Read();
                  }
                  finally
                  {
                        if (myConn.State == ConnectionState.Open)
                              myConn.Close();
                  }
                        Console.Write("Press any key to end...");
                        Console.Read();


            }
      }
}


     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023