using MySql.Data.MySqlClient;
using System.Data;
[HttpGet]
public IActionResult ExecuteQuery(string requestType, string parameter)
{
string connectionString = Configuration.GetConnectionString("DefaultConnection");
string sqlQuery;
sqlQuery = Configuration.GetSection("SqlQueries").GetValue<string>(requestType);
if (string.IsNullOrEmpty(sqlQuery))
{
return BadRequest("Invalid requestType parameter");
}
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
using (MySqlCommand command = new MySqlCommand(sqlQuery, connection))
{
command.Parameters.Add("@param", MySqlDbType.VarChar).Value = parameter;
connection.Open();
DataTable dataTable = new DataTable();
using (MySqlDataAdapter dataAdapter = new MySqlDataAdapter(command))
{
dataAdapter.Fill(dataTable);
}
connection.Close();
string jsonResult = JsonConvert.SerializeObject(dataTable, Formatting.Indented);
return Ok(jsonResult);
}
}
}