Hello good afternoon to all, along with greeting them again bothering with a doubt: I have to fill a datagridview with a stored procedure of mysql, which makes a select and by means of a where limits the query:
CREATE PROCEDURE 'spMedicamentosPorPaciente' (in textobusqueda varchar (45))
BEGIN
SELECT * FROM medicamentos_paciente WHERE idPaciente = textobusqueda LIMIT 150;
END
my project is in layers, in the data and business layer I have a method that allows me to fill the grid without problems:
public DataTable mostrarTabla()
{
DataTable dtProfesionales = new DataTable("profesional");
MySqlConnection con = new MySqlConnection();
try
{
con.ConnectionString = conexion.cadenaConexion;
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = con;
cmd.CommandText = "spMostrarProfesionales";
cmd.CommandType = CommandType.StoredProcedure;
MySqlDataAdapter adaptador = new MySqlDataAdapter(cmd);
adaptador.Fill(dtProfesionales);
}
catch (Exception ex)
{
dtProfesionales = null;
}
return dtProfesionales;
}
and the code in business:
public static DataTable mostrar()
{
return new datosProfesional().mostrarTabla();
}
the issue is that I do not know how to load the datatable show with the stored procedure that has the parameter, I'm trying with this code:
public DataTable mostrarTabla(datosMedicamentosPaciente medpaciente)
{
DataTable dtMedicamentosPaciente = new DataTable("medicamentos_paciente");
MySqlConnection con = new MySqlConnection();
try
{
con.ConnectionString = conexion.cadenaConexion;
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = con;
cmd.CommandText = "spMedicamentosPorPaciente";
cmd.CommandType = CommandType.StoredProcedure;
//DECLARAMOS LOS PARAMETROS QUE SON IGUALES A LOS QUE TENEMOS EN EL SP
MySqlParameter parIdMedPaciente = new MySqlParameter();
parIdMedPaciente.ParameterName = "@textobusqueda";
parIdMedPaciente.MySqlDbType = MySqlDbType.VarChar;
parIdMedPaciente.Value = medpaciente.IdMedicamentoPaciente;
cmd.Parameters.Add(parIdMedPaciente);
MySqlDataAdapter adaptador = new MySqlDataAdapter(cmd);
adaptador.Fill(dtMedicamentosPaciente);
}
catch (Exception ex)
{
dtMedicamentosPaciente = null;
}
return dtMedicamentosPaciente;
}
in the form I have this function to load the grid:
private void cargarGrilla()
{
this.dgvMedicamentos.DataSource = negocioMedicamentos.mostrar(this.txtCodPaciente.Text);
//this.ocultarColumnas();
//lblTotalRegistros.Text = "Total de Registros: " + Convert.ToString(dgvBoxes.Rows.Count);
}
but it throws me the following errors:
Error 3 No overload for the 'show' method takes '1' arguments. XXXXXXX \ CapaPresentacion \ frmMedicamentosPaciente.cs 36 47 CapaPresentacion
Error 4 No overload for the 'showTable' method takes '1' arguments XXXXXX \ CapaNegocios \ negocioMedicamentosPaciente.cs 47 20 CapaNegocios
Greetings to all and thanks