从c#调用过程中,它显示以下错误
“在数据库'
get_Users()'
'中找不到过程或函数'CALL
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;
}
答案 0 :(得分:2)
如果我错了,请纠正我,但是我认为您可以在没有CALL关键字和()的情况下调用存储过程。从那以后,您已经在System.Data.CommandType.StoredProcedure
上拍摄了该命令。
所以您可以尝试MySqlCommand("get_Users", Conn)
答案 1 :(得分:0)
您有一个虚假的背景。使用这个:
MySqlCommand command = new MySqlCommand("CALL get_Users();", Conn);
或者,您也可能带有虚假的下划线。在这种情况下,请使用:
MySqlCommand command = new MySqlCommand("CALL getUsers();", Conn);
目前还不清楚get_Users()
到底是什么。也许您应该发布它的定义,我们会看看发生了什么。
另外,尝试通过键入以下命令直接从MySQL管理控制台执行命令:
use <database-name>;
CALL get_Users();
或
use <database-name>;
CALL getUsers();
看看它返回什么。如果无法通过管理控制台正常运行,则可能无法从其他任何地方使用。