if you are using SQL Server, the simpler way is to use SQL statement like this:
select top 1 * from yourtable order by SomeIDOrDateTimeField DESCotherwise, if you do 
select * from yourtableand if you are using DataSet, then just get
ds.Rows[ds.Rows.Count-1]["字段"]if you are using SqlDataReader, then you need to do something likeString s;
while (dr.Read())
  s = (String)dr["字段"];

解决方案 »

  1.   

    select top 1 * from yourtable order by SomeIDOrDateTimeField DESC
    是反会一个数据集吗?该怎样提取某一个字段的值?
    谢谢!
      

  2.   

    it returns only one record, SqlConnection myConnection = new SqlConnection(myConnectionString);
    SqlCommand myCommand = new SqlCommand("select top 1 * from yourtable order by SomeIDOrDateTimeField DESC", myConnection);
    myCommand.Connection.Open();
    SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
    if (myReader.Read())
    {
          System.Console.WriteLine(myReader["YourField"].ToString());
    }myReader.Close();or better yet, if you only need that one column, you can use ExecuteScalar(), for example:SqlConnection conn = new SqlConnection("Server=localhost;Database=pubs;UID=sa;PWD=;");
    SqlCommand cmd = new SqlCommand("Select top 1 au_lname from authors order by au_lname desc",conn);
    conn.Open();
    String s = (String)cmd.ExecuteScalar();
    Console.WriteLine(s);
    conn.Close();