27/7/10

Añadir consultas a un DataAdapter por código

El problema es que si se hace gráficamente, al rehacer el DataSet, se borran.
Para solucionarlo hay que heredar del DataAdapter generado y crear los Fill que se quieran.

public class AdapterModificado : DSTableAdapters.EnteTableAdapter
{
public void FillByNif(DS.EnteDataTable t,string nif)
{
SqlCeCommand aux = this.CommandCollection[0];
this.CommandCollection[0] = new SqlCeCommand("select * from ente where nif = @nif");
this.CommandCollection[0].Connection = this.Connection;
this.CommandCollection[0].Parameters.Add("@nif", nif);
this.Fill(t);
this.CommandCollection[0] = aux;
}
}