dataset into listbox - one works but the other doesn't

chime

Member
Joined
Jul 12, 2005
Messages
22
Location
wexford, Ireland
Programming Experience
3-5
Hi

I have a web page consisting of two listboxes

ListBoxPublicHolidaysAvailable and ListBoxPublicHolidaysAvailable

which are both populated by Datasets.

The code is working for the first one (ListBoxPublicHolidaysAvailable)

but not the second ListBoxPublicHolidaysAvailable)

I am reading the code from a my sql database

The second dataset is populated and the error occurs at this point

If DataSetPublicHolidaysSelected.ATTENDANCE_DaysInLieu.Rows.Count = 0 Then

Else

' Only show the data if there are rows to load

ListBoxPublicHolidaysSelected.DataSource = DataSetPublicHolidaysSelected

ListBoxPublicHolidaysSelected.DataTextField = "Holiday"

ListBoxPublicHolidaysSelected.DataBind()

End If

The errors occurs with and without the if statement

the error is as follows



Message "Object reference not set to an instance of an object."

Yet in the if statement DataSetPublicHolidaysSelected.ATTENDANCE_DaysInLieu.Rows.Count is greater than 1 in some cases.











________________________________________________________________________________





Public
Class GrantDayInLieu

Inherits System.Web.UI.Page

Dim strAttnConsoleFormLink As String = "AttnConsole.aspx"

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Dim configurationAppSettings As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader

Me.OdbcConnectionEIDB = New System.Data.Odbc.OdbcConnection

Me.OdbcDataAdapterPublicHolidaysAvailable = New System.Data.Odbc.OdbcDataAdapter

Me.OdbcSelectCommandPublicHolidaysAvailable = New System.Data.Odbc.OdbcCommand

Me.OdbcDataAdapterPublicHolidaysSelected = New System.Data.Odbc.OdbcDataAdapter

Me.OdbcSelectCommandPublicHolidaysSelected = New System.Data.Odbc.OdbcCommand

Me.DataSetPublicHolidaysAvailable = New Attendance_WEB.DataSetPublicHolidaysAvailable

Me.DataSetPublicHolidaysSelected = New Attendance_WEB.DataSetPublicHolidaysSelected

CType(Me.DataSetPublicHolidaysAvailable, System.ComponentModel.ISupportInitialize).BeginInit()

CType(Me.DataSetPublicHolidaysSelected, System.ComponentModel.ISupportInitialize).BeginInit()

'

'OdbcConnectionEIDB

'

Me.OdbcConnectionEIDB.ConnectionString = CType(configurationAppSettings.GetValue("STMT=;OPTION=3;DSN=EIDB;UID=webdata;USER=webdata;DESC=MySQL ODBC 3.51 Driver DSN;" & _

"DATABASE=PFPC-International;SERVER=Odyssey;PORT=3306", GetType(System.String)), String)

'

'OdbcDataAdapterPublicHolidaysAvailable

'

Me.OdbcDataAdapterPublicHolidaysAvailable.SelectCommand = Me.OdbcSelectCommandPublicHolidaysAvailable

Me.OdbcDataAdapterPublicHolidaysAvailable.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "ATTENDANCE_PublicHolidays", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("Holiday", "Holiday"), New System.Data.Common.DataColumnMapping("ObservedDate", "ObservedDate")})})

'

'OdbcSelectCommandPublicHolidaysAvailable

'

Me.OdbcSelectCommandPublicHolidaysAvailable.CommandText = "SELECT Holiday, ObservedDate FROM ATTENDANCE_PublicHolidays"

Me.OdbcSelectCommandPublicHolidaysAvailable.Connection = Me.OdbcConnectionEIDB

'

'OdbcDataAdapterPublicHolidaysSelected

'

Me.OdbcDataAdapterPublicHolidaysSelected.SelectCommand = Me.OdbcSelectCommandPublicHolidaysSelected

Me.OdbcDataAdapterPublicHolidaysSelected.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "ATTENDANCE_DaysInLieu", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("FFNumber", "FFNumber"), New System.Data.Common.DataColumnMapping("Holiday", "Holiday"), New System.Data.Common.DataColumnMapping("DIL", "DIL")})})

'

'OdbcSelectCommandPublicHolidaysSelected

'

Me.OdbcSelectCommandPublicHolidaysSelected.CommandText = "SELECT Holiday, DIL FROM ATTENDANCE_DaysInLieu"

Me.OdbcSelectCommandPublicHolidaysSelected.Connection = Me.OdbcConnectionEIDB

'

'DataSetPublicHolidaysAvailable

'

Me.DataSetPublicHolidaysAvailable.DataSetName = "DataSetPublicHolidaysAvailable"

Me.DataSetPublicHolidaysAvailable.EnforceConstraints = False

Me.DataSetPublicHolidaysAvailable.Locale = New System.Globalization.CultureInfo("en-IE")

'

'DataSetPublicHolidaysSelected

'

Me.DataSetPublicHolidaysSelected.DataSetName = "DataSetPublicHolidaysSelected"

Me.DataSetPublicHolidaysSelected.EnforceConstraints = False

Me.DataSetPublicHolidaysSelected.Locale = New System.Globalization.CultureInfo("en-IE")

CType(Me.DataSetPublicHolidaysAvailable, System.ComponentModel.ISupportInitialize).EndInit()

CType(Me.DataSetPublicHolidaysSelected, System.ComponentModel.ISupportInitialize).EndInit()

End Sub

Protected WithEvents lblITDev As System.Web.UI.WebControls.Label

Protected WithEvents btnExit As System.Web.UI.WebControls.Button

Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm

Protected WithEvents DIV1 As System.Web.UI.HtmlControls.HtmlGenericControl

Protected WithEvents OdbcConnectionEIDB As System.Data.Odbc.OdbcConnection

Protected WithEvents OdbcDataAdapterPublicHolidaysSelected As System.Data.Odbc.OdbcDataAdapter

Protected WithEvents OdbcDataAdapterPublicHolidaysAvailable As System.Data.Odbc.OdbcDataAdapter

Protected WithEvents OdbcSelectCommandPublicHolidaysSelected As System.Data.Odbc.OdbcCommand

Protected WithEvents OdbcSelectCommandPublicHolidaysAvailable As System.Data.Odbc.OdbcCommand

Protected WithEvents DataSetPublicHolidaysAvailable As Attendance_WEB.DataSetPublicHolidaysAvailable

Protected WithEvents DataSetPublicHolidaysSelected As Attendance_WEB.DataSetPublicHolidaysSelected

Protected WithEvents lblAvailableTitle As System.Web.UI.WebControls.Label

Protected WithEvents lblSelectedTitle As System.Web.UI.WebControls.Label

Protected WithEvents lblAvailableCount As System.Web.UI.WebControls.Label

Protected WithEvents lblSelectedCount As System.Web.UI.WebControls.Label

Protected WithEvents ListBoxPublicHolidaysSelected As System.Web.UI.WebControls.ListBox

Protected WithEvents ListBoxPublicHolidaysAvailable As System.Web.UI.HtmlControls.HtmlSelect

'NOTE: The following placeholder declaration is required by the Web Form Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region



Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

' If its a postback (not the initial page load)

If IsPostBack Then

Else

End If

'Put user code to initialize the page here

fill_PublicHolidaysAvailable()

fill_PublicHolidaysSelected()

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

' Change to the Attendance Console Form

Response.Redirect(strAttnConsoleFormLink)

End Sub



' Fill Absence Datagrid

Private Sub fill_PublicHolidaysAvailable()

' select the country luxemburg, ireland or usa

Dim strLocation As String

Select Case Session("Location").ToString

'if any of the options are selected

Case "Luxemburg"

strLocation = "LUX"

Case "Dublin"

strLocation = "IRL"

Case "Navan"

strLocation = "IRL"

Case "Wexford"

strLocation = "IRL"

Case Else

strLocation = "USA"

End Select

Try

' Fill the Available Public holidays according to location

OdbcSelectCommandPublicHolidaysAvailable.CommandText = "SELECT Holiday, ObservedDate, AMPM " & _

"FROM ATTENDANCE_PublicHolidays " & _

"WHERE (ObservedBy LIKE '" & strLocation & "' OR ObservedBy LIKE 'ALL' ) " & _

"ORDER BY ObservedDate"

DataSetPublicHolidaysAvailable.Clear()

' Fill the dataset

OdbcDataAdapterPublicHolidaysAvailable.Fill(DataSetPublicHolidaysAvailable)

' Show the data

ListBoxPublicHolidaysAvailable.DataSource = DataSetPublicHolidaysAvailable

ListBoxPublicHolidaysAvailable.DataTextField =
"Holiday"

ListBoxPublicHolidaysAvailable.DataBind()

' How many Public holidays are available (always a whole number)

lblAvailableCount.Text = DataSetPublicHolidaysAvailable.ATTENDANCE_PublicHolidays.Rows.Count.ToString

Catch ex As Exception

End Try

End Sub



Private Sub fill_PublicHolidaysSelected()

Dim strFFNumber As String = Session("UserID").ToString

Try

' Fill the Selected Public holidays for the user

OdbcSelectCommandPublicHolidaysSelected.CommandText = "SELECT Holiday, DIL " & _

"FROM ATTENDANCE_DaysInLieu " & _

"WHERE FFNumber LIKE '" & strFFNumber & "' " & _

"ORDER BY DIL"

DataSetPublicHolidaysSelected.Clear()

' Fill the dataset

OdbcDataAdapterPublicHolidaysSelected.Fill(DataSetPublicHolidaysSelected)

If DataSetPublicHolidaysSelected.ATTENDANCE_DaysInLieu.Rows.Count = 0 Then

Else

' Only show the data if there are rows to load

ListBoxPublicHolidaysSelected.DataSource = DataSetPublicHolidaysSelected

ListBoxPublicHolidaysSelected.DataTextField =
"Holiday"

ListBoxPublicHolidaysSelected.DataBind()

End If

' How many days in lieu have been choosen

lblSelectedCount.Text = DataSetPublicHolidaysSelected.ATTENDANCE_DaysInLieu.Rows.Count.ToString

Catch ex As Exception

End Try

End Sub

End
Class



____________________________________________________________________________________________





<
FORM id="Form1" method="post" runat="server">

<DIV id="DIV1" style="TABLE-LAYOUT: fixed; BORDER-LEFT-COLOR: firebrick; BORDER-BOTTOM-COLOR: firebrick; OVERFLOW: hidden; WIDTH: 902px; CURSOR: hand; BORDER-TOP-COLOR: firebrick; POSITION: relative; BORDER-COLLAPSE: separate; HEIGHT: 670px; BORDER-RIGHT-COLOR: firebrick"

ms_positioning="GridLayout" runat="server">

<P> </P>

<asp:label id="lblITDev" style="Z-INDEX: 101; LEFT: 664px; POSITION: absolute; TOP: 568px"

runat="server" Width="121px" Font-Size="XX-Small" Height="10px">IT Development June 2005</asp:label><asp:button id="btnExit" style="Z-INDEX: 102; LEFT: 696px; POSITION: absolute; TOP: 8px" runat="server"

Width="65px" Height="32px" ForeColor="Firebrick" Text="Exit" Font-Bold="True"></asp:button><asp:label id="lblAvailableTitle" style="Z-INDEX: 103; LEFT: 48px; POSITION: absolute; TOP: 80px"

runat="server" Font-Size="Larger">Public Holidays Available</asp:label><asp:label id="lblSelectedTitle" style="Z-INDEX: 104; LEFT: 448px; POSITION: absolute; TOP: 80px"

runat="server" Font-Size="Larger">Public Holidays Selected</asp:label>

<TABLE id="Table1" style="Z-INDEX: 105; LEFT: 48px; WIDTH: 210px; POSITION: absolute; TOP: 424px; HEIGHT: 27px"

cellSpacing="1" cellPadding="1" width="210" border="1">

<TR>

<TD style="WIDTH: 177px">

<asp:Label id="lblAvailable" runat="server" Width="186px" Height="10px" Font-Bold="True">Public Holidays remaining :</asp:Label></TD>

<TD>

<asp:Label id="lblAvailableCount" runat="server" Width="34px" Height="10px" Font-Bold="True">0</asp:Label></TD>

</TR>

</TABLE>

<TABLE id="Table2" style="Z-INDEX: 106; LEFT: 448px; WIDTH: 218px; POSITION: absolute; TOP: 424px; HEIGHT: 30px"

cellSpacing="1" cellPadding="1" width="218" border="1">

<TR>

<TD style="WIDTH: 187px; HEIGHT: 26px">

<asp:Label id="lbl" runat="server" Width="192px" Height="10px" Font-Bold="True">Total Days in Lieu granted :</asp:Label></TD>

<TD style="HEIGHT: 26px">

<asp:Label id="lblSelectedCount" runat="server" Width="34px" Height="10px" Font-Bold="True">0</asp:Label></TD>

</TR>

</TABLE>

<SELECT id="ListBoxPublicHolidaysAvailable" style="TABLE-LAYOUT: fixed; Z-INDEX: 107; LEFT: 40px; OVERFLOW: auto; WIDTH: 272px; CURSOR: hand; POSITION: absolute; TOP: 112px; BORDER-COLLAPSE: separate; HEIGHT: 300px"

size="18" name="ListBoxPublicHolidaysAvailable" runat="server">

<OPTION></OPTION>

</SELECT><SELECT id="ListBoxPublicHolidaysSelecte" style="TABLE-LAYOUT: fixed; Z-INDEX: 108; LEFT: 440px; OVERFLOW: auto; WIDTH: 304px; CURSOR: hand; POSITION: absolute; TOP: 104px; BORDER-COLLAPSE: separate; HEIGHT: 312px"

size="19" name="ListBoxPublicHolidaysSelecte" runat="server">

<OPTION></OPTION>

</SELECT></DIV>

</FORM>

 
Resolved


This

</SELECT><SELECTid="ListBoxPublicHolidaysSelecte"style="TABLE-LAYOUT: fixed; Z-INDEX: 108; LEFT: 440px; OVERFLOW: auto; WIDTH: 304px; CURSOR: hand; POSITION: absolute; TOP: 104px; BORDER-COLLAPSE: separate; HEIGHT: 312px"

Should be

</SELECT><SELECTid="ListBoxPublicHolidaysSelected"style="TABLE-LAYOUT: fixed; Z-INDEX: 108; LEFT: 440px; OVERFLOW: auto; WIDTH: 304px; CURSOR: hand; POSITION: absolute; TOP: 104px; BORDER-COLLAPSE: separate; HEIGHT: 312px"

 
Back
Top