//linq to dataset
string strCon = "Data Source=.;Initial Catalog=Test;User ID=sa;Password=123";
SqlConnection con = new SqlConnection(strCon);
string strSQL = "SELECT [ProductID],[ProductName],[ProductOrigin],[ProductCategory] FROM [Test].[dbo].[tb_Products]";
if (con.State == ConnectionState.Closed)
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(strSQL, con);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
var tmp = from products in dt.AsEnumerable() orderby products.Field<int>("ProductID") descending select products;
// var tmp = from products in dt.AsEnumerable() select products.Field<int>("ProductID");
//var tmp = dt.AsEnumerable().Select (p => new { ProductID = p.Field<Int32>("ProductID"), ProductName = p.Field<string>("ProductName"), ProductOrigin = p.Field<string>("ProductOrigin") });
datarow
foreach (var tmpinfo in tmp)
{
Console.WriteLine("{0}\t{1}\t{2}", tmpinfo.Field<Int32>("ProductID"), tmpinfo.Field<string>("ProductName"), tmpinfo.Field<string>("ProductOrigin"));
//Console.WriteLine("{0}", dr);
// Console.WriteLine("{0}\t{1}\t{2}", tmpinfo.ProductID, tmpinfo.ProductName, tmpinfo.ProductOrigin);
}
}
else
con.Close();