We’ve developed some resources to help you work effectively from home during COVID-19 Click to learn more

Limit the number of records returned from select

I want to limit the number of records returned by the ExecuteReader() but it doesn't take any parameters.

AppointmentTableInfo at = TablesInfo.GetAppointmentTableInfo();
TextTableInfo tt = TablesInfo.GetTextTableInfo();
Select s = S.NewSelect();
s.ReturnFields.Add(at.AppointmentId, tt.Text);
s.JoinRestriction.InnerJoin(at.AppointmentId.Equal(tt.TextId));
s.Restriction = tt.Text.Like(Mask.Mask);
s.OrderBy = new OrderBy(tt.Text);
foreach (ISoDataRecord row in s.ExecuteReader(0, 100)) //no such thing as paging
{
    EntityElement e = new EntityElement();
    e.Id = row.GetInt32(at.AppointmentId);
    e.DisplayValue = getLineOne(row.GetString(tt.Text));
    response.Entities.Add(e);
}

What can I do?.

RE: Limit the number of records returned from select

More code is better? ;-o) I'll have to test but it compiles!

 

AppointmentTableInfo at = TablesInfo.GetAppointmentTableInfo();
TextTableInfo tt = TablesInfo.GetTextTableInfo();
Select sel = S.NewSelect();
sel.ReturnFields.Add(at.AppointmentId, tt.Text);
sel.JoinRestriction.InnerJoin(at.AppointmentId.Equal(tt.TextId));
sel.Restriction = tt.Text.Like(Mask.Mask);
sel.OrderBy = new OrderBy(tt.Text);
using (SoConnection con = ConnectionFactory.GetConnection())
{
    using (SoCommand cmd = con.CreateCommand())
    {
        cmd.SqlCommand = sel;
        con.Open();
        using (SoDataReader reader = cmd.ExecuteReader(Mask.MaxCount, 0))
        {
            while (reader.Read())
            {
                EntityElement e = new EntityElement();
                e.Id = reader.GetInt32(at.AppointmentId);
                e.DisplayValue = getLineOne(reader.GetString(tt.Text));
                response.Entities.Add(e);
            }
        }
    }
}
By: Martin K. Andersen 22 Sep 2020