TableadApter use SqlDataAdapter, which already has this feature.
What to do:
Click on Fill() or FillByXXX() method
myTradesTableAdapter.Fill(...)
and press F12 - it will bring you to its source code generated by designer.
Copy this method.
Go to the DataSet designer, click on table adapter and press F7 - it will create/open code for the TableAdapters namespace.
Paste Fill() method here and modify it some like in example below:
namespace MyApp.DsMyDataTableAdapters {
public partial class MyTradesTableAdapter
{
//// copy-paste method from generated Fill()
//// and make new name: Fill() ==> FillTop()
//// use the same params and add new one: int topN
public virtual int FillTop( //
DsMyData.MyTradesDataTable dataTable,
int someParameterId,
// ...
int topN) // add new param
{
// original code:
this.Adapter.SelectCommand = this.CommandCollection[0];
this.Adapter.SelectCommand.Parameters[1].Value = someParameterId;
if ((this.ClearBeforeFill == true))
{
dataTable.Clear();
}
// modified code
int returnValue = 0;
if (topN > 0) // validate topN
{
// get topN rows
returnValue = this.Adapter.Fill(0, topN, dataTable);
}
else
{
// get all rows (original code) in case topN = 0 or negative
returnValue = this.Adapter.Fill(dataTable);
}
return returnValue;
}
// ....
}
and then you can use it as:
int somePrm = 123;
myTradesTableAdapter.Fill(ds.myTradesTable, somePrm) // original - get all rows
myTradesTableAdapter.FillTop(ds.myTradesTable, somePrm, 100) // new - get 100 rows