Good morning, I have this Web Service that provides me with all the data of a table and all the columns, how do I select only some Columns and not all?
[WebMethod]
public DataTable consultaIndividualSUCIS(int tipoCodigoEntidad, int estadoAutorizacion)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Idoneidad_Funcionarios WHERE tipoCodigoEntidad = @tipoCodigoEntidad AND estadoAutorizacion = @estadoAutorizacion"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Parameters.AddWithValue("@tipoCodigoEntidad", tipoCodigoEntidad); // <-- Este es el parámetro de SQL que estás recibiendo cómo parámetro en tu método
cmd.Parameters.AddWithValue("@estadoAutorizacion", estadoAutorizacion); // <-- Este es el parámetro de SQL que estás recibiendo cómo parámetro en tu método
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
dt.TableName = "Idoneidad_Funcionarios";
sda.Fill(dt);
return dt;
}
}
}
}
}
the table is as follows:
+---------+-----------+-----------+------------+
|tipCod | Nombre |estadoAut |fechaInicio |
+---------+-----------+-----------+------------+
|101 |Pepe |Activo |2017/05/01 |
+---------+-----------+-----------+------------+
In the results I just want to get and that the search parameter is [tipCod]:
+-----------+-----------+------------+
| Nombre |estadoAut |fechaInicio |
+-----------+-----------+------------+
|Pepe |Activo |2017/05/01 |
+-----------+-----------+------------+