gpt4 book ai didi

c# - 调用 MySQL Procedure 出现异常 "procedure cannot be found"

转载 作者:行者123 更新时间:2023-11-30 22:57:21 27 4
gpt4 key购买 nike

在从 c# 调用过程中显示以下错误

"Procedure or function 'CALL get_Users()'cannot be foundin database 'joomla'."`

代码如下

public ObservableCollection<Users> loadUserData()
{

ObservableCollection<Users> UserDetials = new ObservableCollection<Users>();
Users users;
using (MySqlConnection Conn = new MySqlConnection(DataBaseConnection))
{
Conn.Open();

MySqlCommand command = new MySqlCommand("CALL `get_Users();", Conn); // uasing this one it showing Error

// MySqlCommand command = new MySqlCommand("select * from users", Conn); -- if this code run it's taking data from the database

command.CommandType = System.Data.CommandType.StoredProcedure;

using (var cursor = command.ExecuteReader())
{
while (cursor.Read())
{
users = new Users();
users.UserId = Convert.ToInt64(Reader["id"]);
users.UserName = Convert.ToString(Reader["Name"]);
UserDetials.Add(users);
}
}
}
return UserDetials;

}
  • 附上图片enter image description here

最佳答案

如果我错了请纠正我,但我认为您可以在没有 CALL 关键字和 () 的情况下调用您的存储过程。因为,您已经在 System.Data.CommandType.StoredProcedure 上发出命令。

所以你可以尝试 MySqlCommand("get_Users", Conn)

关于c# - 调用 MySQL Procedure 出现异常 "procedure cannot be found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53717828/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com