Vu Hong Trieu

Vu Hong Trieu

  • NA
  • 107
  • 6.6k

MySql stored procedure not exist with C# .NET

Aug 11 2017 5:27 PM
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
  1. DELIMITER $$  
  2. USE `demo`$$  
  3. DROP PROCEDURE IF EXISTS `loadtable`$$  
  4. CREATE DEFINER=`root`@`localhost` PROCEDURE `loadtable`()  
  5. BEGIN  
  6.         SELECT * FROM tablesx;         
  7.     END$$  
  8.  DELIMITER ; 
 My code
1. loadData method
  1. public void loadData(tables model)  
  2.        {  
  3.            connect();  
  4.            ds= new DataSet();  
  5.            MySqlParameter[] prams = {  
  6.                                MakeInParam("@id",MySqlDbType.Int32,4,model.id)  
  7.                            };  
  8.            RunProcDS("loadtable", prams, out ds);  
  9.          } 
 2. RunProcDS method
  1. public int RunProcDS(string procName, MySqlParameter[] prams, out DataSet dataSet)  
  2.         {  
  3.             DataSet ds;  
  4.             MySqlCommand cmd = CreateCommand(procName, prams);  
  5.             MySqlDataAdapter dad = new MySqlDataAdapter(cmd);  
  6.             MySqlCommandBuilder cb = new MySqlCommandBuilder(dad);  
  7.             ds = new DataSet();  
  8.             dad.Fill(ds, "CurrentItems");  
  9.             dataSet = ds;  
  10.             this.Close();  
  11.             return (int)cmd.Parameters["ReturnValue"].Value;  
  12.         } 
 Has error att line 08 " dad.Fill(ds, "CurrentItems"); "
 3. CreateCommand method
  1. private MySqlCommand CreateCommand(string procName, MySqlParameter[] prams)  
  2.         {  
  3.             Open();  
  4.             MySqlCommand cmd = new MySqlCommand(procName, con);  
  5.             if (cmd.Parameters.Count > 0)  
  6.             {  
  7.                 cmd.Parameters.Clear();  
  8.             }  
  9.             cmd.CommandType = CommandType.StoredProcedure;  
  10.             if (prams != null)  
  11.             {  
  12.                 foreach (MySqlParameter parameter in prams)  
  13.                     cmd.Parameters.Add(parameter);  
  14.             }  
  15.             cmd.Parameters.Add(  
  16.                 new MySqlParameter("ReturnValue", MySqlDbType.Int32, 4,  
  17.                 ParameterDirection.ReturnValue, false, 0, 0,  
  18.                 string.Empty, DataRowVersion.Default, null));  
  19.   
  20.             return cmd;  
  21.         } 
 Please help.
 
Thanks,

Answers (3)