I am using c#, sqlce, datatable. I select products with this query:
select price from products where productid=myproduct and mydate between startdate and finaldate and clientid=myclient
But it's going to take much time. So I could use a datatable to store products:
datatable prices = new datatable();
prices=this.returntable("select productid,startdate,finaldate,client from products")
for(int i=0;i<allproductsihave;i++) {
product.newprice=this.getmyprice(prices,product.client,product.id,product.date);
}
private decimal getmyprice(datatable products,string myclient, string myproduct, datetime mydate)
{
//how do I do at here the equivalent to first sql query?
//for select a product from a datatable where my date is between 2 dates,
//and client=myclient and productid=myproduct
return Convert.Todecimal(datatable.prices[something]["price"].tostring());
}
In this way I shouldn't connect to the database for each product query. Is it posible?
maybe doing convert.todatetime to startdate and finaldate?