Hi ryutenkan,
Check this example. Now please take its reference and correct your code.
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[] {
new System.Data.DataColumn("Id", typeof(int)),
new System.Data.DataColumn("Test", typeof(int)),
new System.Data.DataColumn("Start", typeof(int)) });
dt.Rows.Add(1, 1, 10);
dt.Rows.Add(2, 1, 15);
dt.Rows.Add(3, 2, 45);
dt.Rows.Add(4, 1, 86);
dt.Rows.Add(5, 2, 69);
dt.Rows.Add(6, 2, 78);
dt.Rows.Add(7, 1, 105);
dt.Rows.Add(8, 2, 43);
dt.Rows.Add(9, 3, 22);
dt.Rows.Add(10, 2, 13);
dt.Rows.Add(11, 1, 79);
dt.Rows.Add(12, 1, 56);
int a = Convert.ToInt32(dt.Compute("MAX(Start)", "Test = 1"));
Response.Write(a + 1);
Response.Write("<br />");
a = Convert.ToInt32(dt.Compute("MAX(Start)", "Test = 1 AND Start < 100"));
Response.Write(a + 1);
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As Data.DataTable = New Data.DataTable()
dt.Columns.AddRange(New Data.DataColumn() {
New Data.DataColumn("Id", GetType(Integer)),
New Data.DataColumn("Test", GetType(Integer)),
New Data.DataColumn("Start", GetType(Integer))})
dt.Rows.Add(1, 1, 10)
dt.Rows.Add(2, 1, 15)
dt.Rows.Add(3, 2, 45)
dt.Rows.Add(4, 1, 86)
dt.Rows.Add(5, 2, 69)
dt.Rows.Add(6, 2, 78)
dt.Rows.Add(7, 1, 105)
dt.Rows.Add(8, 2, 43)
dt.Rows.Add(9, 3, 22)
dt.Rows.Add(10, 2, 13)
dt.Rows.Add(11, 1, 79)
dt.Rows.Add(12, 1, 56)
Dim a As Integer = Convert.ToInt32(dt.Compute("MAX(Start)", "Test = 1"))
Response.Write(a + 1)
Response.Write("<br />")
a = Convert.ToInt32(dt.Compute("MAX(Start)", "Test = 1 AND Start < 100"))
Response.Write(a + 1)
End If
End Sub
Output
106
87