Created
June 18, 2013 19:55
-
-
Save lohithgn/5808701 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[OperationContract] | |
public List<ProductModel> GetTop10ProductsByPrice() | |
{ | |
var prodList = new List<ProductModel>(); | |
string connectionString = ConfigurationManager.ConnectionStrings["NorthwindConnection"] as string; | |
string query = "SELECT TOP 10 ProductID, Name, UnitPrice FROM Product ORDER BY UnitPrice DESC"; | |
using (SqlConnection connection = new SqlConnection(connectionString)) | |
{ | |
SqlCommand command = new SqlCommand(query, connection); | |
command.CommandType = System.Data.CommandType.Text; | |
var reader = command.ExecuteReader(); | |
if (reader != null) | |
while (reader.Read()) | |
{ | |
var cust = new ProductModel | |
{ | |
ProductID = reader.GetInt32(0), | |
ProductName = reader.GetString(1), | |
Price = reader.GetDecimal(2) | |
}; | |
prodList.Add(cust); | |
} | |
return prodList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment