IT虾米网

在 C# 中调用 MySQL 存储过程

leader 2018年06月24日 数据库 1107 0

这段代码演示在 C# 程序中调用 MySQL 的存储过程,没有返回值,没有参数传递。

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); 
} 

评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!