I try connected MySql stored procedure from c# .Net via MySqlDataAdapter but when i fill data to datatable or dataset has error "Additional information: FUNCTION demo.loadtable does not exist".
My stored
- DELIMITER $$
- USE `demo`$$
- DROP PROCEDURE IF EXISTS `loadtable`$$
- CREATE DEFINER=`root`@`localhost` PROCEDURE `loadtable`()
- BEGIN
- SELECT * FROM tablesx;
- END$$
- DELIMITER ;
My code
1. loadData method
- public void loadData(tables model)
- {
- connect();
- ds= new DataSet();
- MySqlParameter[] prams = {
- MakeInParam("@id",MySqlDbType.Int32,4,model.id)
- };
- RunProcDS("loadtable", prams, out ds);
- }
- public int RunProcDS(string procName, MySqlParameter[] prams, out DataSet dataSet)
- {
- DataSet ds;
- MySqlCommand cmd = CreateCommand(procName, prams);
- MySqlDataAdapter dad = new MySqlDataAdapter(cmd);
- MySqlCommandBuilder cb = new MySqlCommandBuilder(dad);
- ds = new DataSet();
- dad.Fill(ds, "CurrentItems");
- dataSet = ds;
- this.Close();
- return (int)cmd.Parameters["ReturnValue"].Value;
- }
3. CreateCommand method
- private MySqlCommand CreateCommand(string procName, MySqlParameter[] prams)
- {
- Open();
- MySqlCommand cmd = new MySqlCommand(procName, con);
- if (cmd.Parameters.Count > 0)
- {
- cmd.Parameters.Clear();
- }
- cmd.CommandType = CommandType.StoredProcedure;
- if (prams != null)
- {
- foreach (MySqlParameter parameter in prams)
- cmd.Parameters.Add(parameter);
- }
- cmd.Parameters.Add(
- new MySqlParameter("ReturnValue", MySqlDbType.Int32, 4,
- ParameterDirection.ReturnValue, false, 0, 0,
- string.Empty, DataRowVersion.Default, null));
- return cmd;
- }
Thanks,
Gokhul VarmanPosted Aug 12, 2017, 1:28 AM
Your RPC completed only means that the batch submitted to SQL Server was correct and completed. It doesn't mean the stored procedure ran and executed OK.
It will be (don't argue, check) one of:
To ensure that things are the same
The OBJECT_ID will be NULL if the stored proc doesn't exist in that database or you don't have permissions.
Vu Hong TrieuPosted Aug 12, 2017, 12:30 AM
Sundaram SubramanianPosted Aug 11, 2017, 11:50 PM