I have a problem, I have stored procedure in my MySQL database called: sp_insertSupplier. This method is working when executed in mysql database.
I make this syntax in Save button
private void btn_supplier_save_Click(object sender, EventArgs e)
{
string connections = Connection.mysqlconnectionbuilder();
using (MySqlConnection conn = new MySqlConnection(connections))
{
using (MySqlCommand cmd = new MySqlCommand())
{
//make connection
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "call sp_insertSupplier(@KD,@NM,@AL,@EM,@TLP);";
cmd.Parameters.AddWithValue("@KD", createCode());
cmd.Parameters.AddWithValue("@NM", txtsuppliernama.Text);
cmd.Parameters.AddWithValue("@AL", txtsupplieralamat.Text);
cmd.Parameters.AddWithValue("@EM", txtsupplieremail.Text);
cmd.Parameters.AddWithValue("@TLP",txtsuppliernotelp.Text);
try
{
conn.Open();
int result = cmd.ExecuteNonQuery();
//check the result status
if (result.Equals(1))
{
DialogResult results = MessageBox.Show("Data berhasil ditambahkan! \n Apakah anda ingin input data lainnya? ", "Sukses!", MessageBoxButtons.OKCancel);
//cek apabila ingin menambahkan data lagi.
if (results.Equals(DialogResult.OK))
{
reset();
}
else if (results.Equals(DialogResult.Cancel))
{
this.Close();
}
}
} //end TRY
catch (Exception exe)
{
MessageBox.Show("Terjadi Kesalahan", "Perhatian!", MessageBoxButtons.OK, MessageBoxIcon.Error);
StreamWriter _writer = new StreamWriter("E899911823.log");
_writer.WriteLine(exe.ToString());
Console.WriteLine(exe.ToString());
} //END CATCH
finally
{
conn.Clone();
} //END FINALLY
}
}
}
but, when I execute the syntax, it shows an error:
MySql.Data.MySqlClient.MySqlException (0x80004005): Procedure or function '`call sp_insertSupplier(@KD,@NM,@AL,@EM,@TLP)`' cannot be found in database XXXXX
I don't think any problems with connection manager or the random method to create @KD.
I have still same problems, the console shows:
MySql.Data.MySqlClient.MySqlException (0x80004005): Procedure or function '`call sp_insertSupplier`' cannot be found in database '`XXXXX`'.
at MySql.Data.MySqlClient.ProcedureCache.GetProcData(MySqlConnection connection, String spName)
at MySql.Data.MySqlClient.ProcedureCache.AddNew(MySqlConnection connection, String spName)
at MySql.Data.MySqlClient.ProcedureCache.GetProcedure(MySqlConnection conn, String spName, String cacheKey)
at MySql.Data.MySqlClient.StoredProcedure.GetParameters(String procName, DataTable& proceduresTable, DataTable& parametersTable)
at MySql.Data.MySqlClient.StoredProcedure.CheckParameters(String spName)
at MySql.Data.MySqlClient.StoredProcedure.Resolve(Boolean preparing)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at SerbaManisInventory.SupplierAdd.btn_supplier_save_Click(Object sender, EventArgs e)
I just rewrite the code so that the code like this:
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "call sp_insertSupplier";
cmd.Parameters.AddWithValue("@KD", createCode());
cmd.Parameters.AddWithValue("@NM", txtsuppliernama.Text);
cmd.Parameters.AddWithValue("@AL", txtsupplieralamat.Text);
cmd.Parameters.AddWithValue("@EM", txtsupplieremail.Text);
cmd.Parameters.AddWithValue("@TLP",txtsuppliernotelp.Text);
try
{
...