How to code for reading a data from select statement?

In my database, I have a table. I want to select the largest number of sequence (an atribute of table) . Here are the codes by C#:

int t_integer;

SqlDataSource dtinput = new SqlDataSource();

dtinput.ConnectionString = ConfigurationManager.ConnectionStrings["connectionString"].ToString();

dtinput.SelectCommand = "SELECT [sequence] from [input] WHERE [sequence] = MAX";

After SELECT statement, I need t_integer equal the largest number of sequence that is queryed by select statement.

t_integer = ---->> the mark should be something including value of sequence

t_integer = t_integer + 1;

What is a correct coding in mark above

Thank you.



Answer this question

How to code for reading a data from select statement?

  • CyanBlue

    Why not use "Select Max(sequence) + 1 from input", this should return the max number in the sequence field plus 1.



  • How to code for reading a data from select statement?