SQL/MySQL/Procedure Function/CSharp — различия между версиями

Материал из SQL эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 13:46, 26 мая 2010

Calling a stored procedured in C#

 
MySqlConnection myConnection;        
myConnection = new MySqlConnection();
myConnection.ConnectionString = "database="+database+";server="+server+";user id="+user+";Password="+password;
try  {
    myConnection.Open();
}
catch (MySqlException MyException)            {
    Console.WriteLine("Connection error: MySQL code: "+MyException.Number
                     +" "+ MyException.Message);
}
try {
            
   MySqlCommand myCommand = new MySqlCommand("call error_test_proc(1)",
                                              myConnection);            
   myCommand.ExecuteNonQuery();
}
catch (MySqlException MyException)            {
   Console.WriteLine("Stored procedure error: MySQL code: " + MyException.Number
                     + "  " + MyException.Message);
}



Get returning value from a stored procedure in C#

 

CallableStatement PreparedFunc = MyConnect.prepareCall("{ ? = call isodd( ? ) }");
PreparedFunc.registerOutParameter(1, Types.INTEGER);
PreparedFunc.setInt(1, aNumber);
PreparedFunc.execute();
if (PreparedFunc.getInt(1) == 1)
     System.out.println(aNumber + " is odd");
else
     System.out.println(aNumber + " is even");