Ang*_*mar 2 c# mysql combobox stored-procedures
我有一个带有两个 OUT 参数的 MySQL 存储过程,如下所示。
CREATE `GetCourses`(out UG varchar(20),out PG varchar(20))
BEGIN
SELECT course_name into UG FROM test_db.courses where group_id=1;
select course_name into PG from test_db.courses where group_id=2;
END
Run Code Online (Sandbox Code Playgroud)
现在在 Windows 窗体中,我有两个组合框,其中第一个组合框应与 OUT 变量 UG 绑定,另一个组合框应与另一个 OUT 变量 PG 绑定。
如何使用 c# 实现这一目标?
提前致谢。
它会是这样的......
//Basic command and connection initialization
MySqlConnection conn = new MySqlConnection(ConnectString);
MySqlCommand cmd = new MySqlCommand("GetCourses", conn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
// Add parameters
cmd.Parameters.Add(new MySqlParameter("?UG", MySqlDbType.VarChar));
cmd.Parameters["?UG"].Direction = ParameterDirection.Output;
cmd.Parameters.Add(new MySqlParameter("?PG", MySqlDbType.VarChar));
cmd.Parameters["?PG"].Direction = ParameterDirection.Output;
// Open connection and Execute
conn.Open();
cmd.ExecuteNonQuery();
// Get values from the output params
string PG = (string)cmd.Parameters["?PG"].Value;
string UG = (string)cmd.Parameters["?UG"].Value;
Run Code Online (Sandbox Code Playgroud)