Walking thr DataReader

L

Lorenzo

Hello There,
I have the following code that I need to optimize but I have somenthing that
doesn't work quite as expected:
I am doing the following: I am coloring a calendar according to dates
present in the DB yellow if the dates are present, blank for available
dates. I have some problems handling NULL values. The following code works
well as long I don't encounter a NULL value because it doesn't do what I'd
like it to do.

It should check each and every row returned and evaluate if the row has a
record, if it does it should then render a yellow background color for my
calendar. I have not included the code that make me select a value from a
DropDownList control and pass it to the query as a parameter. Whan I select
an apartment that contains NULL values it DOES NOT color yellow any other
previous date that were present in the DB for that particular apartment I
simply have everything white.
Why is that, I don't get it. I have this out of hands in the terms that
clearly exits my IF ... THEN statement at the first NULL value that it finds
without rendering the other dates. I hope this explains my situation.



Dim dr as OleDbDataReader
Dim strSQL as String = "SELECT dteDataArrivo, dteDataPartenza FROM
tblPrenotazioni WHERE IDImmobile = " & lstApt.SelectedValue
Dim cmd as New OleDbCommand(strSQL, objConnessione)

objConnessione.Open()
dr = cmd.ExecuteReader()


Do While dr.Read()
If Not IsDBNull(dr.Item(0)) and Not IsDbNull(dr.Item(1)) Then
If (E.Day.Date >= dr.Item(0)) and (E.Day.Date < dr.Item(1)) Then
e.cell.BackColor = System.Drawing.Color.Yellow
End If
Else
e.cell.BackColor = System.Drawing.Color.White
lblErrors.Text= "Empty Dates founds"
End If
Loop

objConnessione.Close()



Thanks for your help
L.
 
J

JDP@Work

I'm not sure if you can get the code as you have it to work.

You may wish to review the ItemDataBound event.

Do a google for ItemDataBound Event

--- snipit ( .... dots indicate lots of missing code.... )

Private Sub refresh(ByVal whichStep As EstimatorStepType)
.....
Select Case whichStep
Case EstimatorStepType.Overview
Me.td1.Text = reportDate
Me.lblExtractDate1.Text = extractDate
Me.formatPeriodNamesInDataGrids(ds)
Me.dgOverview.DataSource = ds.Tables(1)
'Here's where the ItemDataBound is called....
---->>> Me.dgOverview.DataBind()
Case EstimatorStepType.Region
Me.td2.Text = reportDate
.......' at databind we end up here, which in my case processes a number of
datagrids on one page
Private Sub dg_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles _
dgOverview.ItemDataBound, dgRegionSummary.ItemDataBound,
dgDirectorSummary.ItemDataBound, dgMCSummary.ItemDataBound
......
ElseIf e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
...... 'find a control
Dim lbl_estAWRV As Label = e.Item.FindControl("lblEst_AWRV")
......' do something
......' find another control & change it's color, in this case any scheduled item
in the past
If e.Item.DataItem("est_install_date") < Date.Now Then
e.Item.Cells(3).ForeColor = System.Drawing.Color.Red
End If
......

HTH

JeffP....

"Lorenzo"
<CuTT-!thISoFfonlyLeAveMyNamelorenzoWithNoNuMBErS98776@LeaveMyCountry!!!ITALIANl
odging.it.NOSPAM> wrote in message news:[email protected]...
 
L

Lorenzo

Hello, thanks for the reply

I am within a CalendarControl onDayRender event that I am sure will get
rendered the same way a DataGrid does but is there anything simpler?

If not I will just avoid inserting NULL values in the DB...

Sorry I am beginner...
L.
 
J

JDP@Work

Lorenzo,

To that end of not inserting nulls, I usually have an sProc return my data,
there I can transform nulls into empty values.

For example if I have a process for sales, I would never have a sale dated,
1/1/1951, but that date can be used for logically setting my color.

Since any null date is returned as such I can test and set my properties.

HTH

JeffP....


"Lorenzo"
<CuTT-!thISoFfonlyLeAveMyNamelorenzoWithNoNuMBErS98776@LeaveMyCountry!!!ITALIANl
odging.it.NOSPAM> wrote in message news:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top