Hi, i have a cost issue with datatable. And i need to replace the code with a smarter one.
i have a datatable and the sample values are like this:
Columns : id, user_id, starttime, endtime
Row Sample : 1 , 5, 05.10.2009 08:00:00,05.10.2009 17:00
my pseudo code is
function something()
{
for(int i=0;i<datatable.Rows.Length;i++)
{
if(Someobject.variable.Equals(dt.Rows[i][user_id].ToString()))
{
if(Date.Compare(somevariable,dt.Rows[i][starttime].ToString())!=0)
{
//Do something
}
}
}
}
it's something like that. The datatable has more than a thousand rows and the functions has to be called nearly a thousand times when the asp.net page loads.
So i have to change it.
i considered using dictionary but it seems that it takes only two variables. What can you suggest me.
Edit:
I could not solve the problem yet. Here is the related code. Thanks in advance.
protected void RadScheduler_Randevu_TimeSlotCreated(object sender, Telerik.Web.UI.TimeSlotCreatedEventArgs e) {
for (int i = 0; i < calismaSaatleridt.Rows.Count; i++)
{
if (RadScheduler_Randevu.SelectedView.Equals(SchedulerViewType.DayView))
{
if (RadScheduler_Randevu.SelectedDate.ToShortDateString().Equals(Convert.ToDateTime(calismaSaatleridt.Rows[i]["calisma_baslangic"]).ToShortDateString()))
{
if (e.TimeSlot.Resource.Key.ToString().Equals(calismaSaatleridt.Rows[i]["hekim_id"].ToString()))
{
if (DateTime.Compare(e.TimeSlot.Start, Convert.ToDateTime(calismaSaatleridt.Rows[i]["calisma_baslangic"])) < 0 || DateTime.Compare(e.TimeSlot.End, Convert.ToDateTime(calismaSaatleridt.Rows[i]["calisma_bitis"])) > 0)
{
e.TimeSlot.CssClass = "Disabled";
}
}
}
}
}
}
This is the function that returns the result set.
private DataTable calismaSaatiGetir(string yonetici_id)
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand command = new SqlCommand();
command.CommandText = "select calisma_saati.id,kullanici.id as hekim_id,LEFT(CONVERT(VARCHAR,calisma_saati.tarih,104),10)+ ' ' +LEFT(CONVERT(VARCHAR,calisma_saati.baslangic_saati,108),5) AS calisma_baslangic,LEFT(CONVERT(VARCHAR,calisma_saati.tarih,104),10)+ ' '+LEFT(CONVERT(VARCHAR,calisma_saati.bitis_saati,108),5) AS calisma_bitis from calisma_saati JOIN kullanici ON kullanici.id=calisma_saati.kullanici_id WHERE yonetici_id='" + Session["yonetici"].ToString() + "' ";
command.Connection = connection;
connection.Open();
SqlDataAdapter da = new SqlDataAdapter(command.CommandText, connection);
DataSet ds = new DataSet();
da.Fill(ds, "calisma_saati");
calismaSaatleridt = ds.Tables["calisma_saati"];
connection.Close();
return calismaSaatleridt;
}