how do we can call stored procedure with json array as input to store procedure from .Net ? I tried below code but it doesnt work.
sql:
CREATE OR REPLACE PROCEDURE ReportData(jsonArray ARRAY(json)) AS
DECLARE
C# code
var connMySQL = new MySql.Data.MySqlClient.MySqlConnection();
int Timeout = 1900;
System.Data.IDbCommand cmd;
string sSql;
object rowCnt;
string stored_procedure = “ReportData”;
string myConnectionString = "Server=s;Port=3306;Uid=;Pwd=;Database=;checkparameters=false";
var jsonRequest = new { items = new[] {
new
{
case_name = "tes", view = "gg", acct_account_code = "888-0000", busn_business_code = "888", func_function_code = "000" , enty_entity_code = "000", proj_project_code = "000" , time_month = "JAN",
time_year = "2021" , layr_layer_code = "kk" , dimension1_code = "77" , cellid ="9"
}
}
};
try
{
var json1 = System.Text.Json.JsonSerializer.Serialize(jsonRequest);
connMySQL.ConnectionString = myConnectionString;
connMySQL.Open();
if (connMySQL.State == System.Data.ConnectionState.Open)
{
connMySQL.Open();
MySqlCommand cmd1 = connMySQL.CreateCommand();
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.CommandText = stored_procedure;
cmd1.Parameters.Add(new MySqlParameter("@jsonArray", MySqlDbType.JSON) { Value = json1 });
MySqlDataReader rdr = cmd1.ExecuteReader();
while (rdr.Read())
{
Console.WriteLine(rdr[0] + " --- " + rdr[1]);
}
rdr.Close();
connMySQL.Close();
}
}
catch(Exception ex)
{
string ex1 = ex.ToString();
}