Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i have done some connections to database as well as the filling of dataset.. ... ..only to realize that to use the records in that dataset, the only possible way is to establish connections and fill it in the same method as in which i want its values to be displayed.

 

The connection has to be done once again if i were to access the intTotalRow count in another method.

 

intTotalRow = datasetTest.Tables(strTblName).Rows.Count

 

the reason i wanna separated intTotalRow count to another method instead of putting it with my dataset Connection is that the codes can be reused. To save lines.. i created my own method with parameters..

 

Pls Help...

Thank you

Posted (edited)

may i show my codes..

   Sub ddlTime_Changed(ByVal sender As Object, ByVal e As System.EventArgs)
       Dim dtTempTime As Date
       lblErrMsg.Text = lblErrMsg.Text & "in ddltime_selectedchanged"
       If (ddlChosenDate.SelectedIndex = 0) Then
           strTempTime = CStr(ddlTimeSlots.SelectedItem.Text)
           dtTempTime = CDate(strTempTime.Substring(0, 5))
           FormatDateTime(dtTempTime, DateFormat.ShortTime)
           If Not (Request.Cookies("facId") Is Nothing) Then
               intSelectedFacID = Request.Cookies("facID").Value
           End If
           time_date(dtTempTime, intSelectedFacID)
           check_empty_ddl(ddlChosenDate, "time slot")
           ddlChosenDate.AutoPostBack = True
           ddlTimeSlots.AutoPostBack = True
       End If
       lblErrMsg.Text = lblErrMsg.Text & "out ddltime_selectedchanged"
   End Sub

Sub time_date(ByVal paraTime As Date, ByVal paraFacID As Integer)
       If Not (Request.Cookies("FacTotalRows") Is Nothing) Then
           intFacTotalRows = Request.Cookies("FacTotalRows").Value
       End If
       If Not (paraFacID < 0) Then
           Response.Cookies("facID").Value = paraFacID
           Response.Cookies("ErrMsg").Value = "The facility you have selected is invalid. Please re-select."
           Response.Redirect("facBooking.aspx")
       Else
           'instantiate query string
           strBookQuery = "SELECT * FROM FacilityBooking where fabfacIDInt = " & paraFacID

           'Connect to database, invoking module file mehtod
           Call updateDataAdapter(strDBPath, strBookQuery, strBookTblName, objConn, objComm, objAdapter, dsBooked)

           'set the values of dataTable
           tblBook = dsBooked.Tables(strBookTblName)
           'counting the total no. of rows in dataset, dsFac
           intBookTotalRows = CInt(tblBook.Rows.Count)

           For i = 0 To 13 '2 weeks; 14 days
               dtDate = DateAdd(DateInterval.Day, i, Now()) 'adding day by day to check
               'row no.s to transverse through records
               For y = 0 To intBookTotalRows - 1
                   'match if dtDate date and selected timeSlot has been booked
                   If (tblBook.Rows(y).Item("fabDateChosenStr") = dtDate And _
                       tblBook.Rows(y).Item("fabStartTimeStr") = paraTime) Then
                       Exit For 'if yes then 
                   Else
                       'once the last record reached
                       While (y = intBookTotalRows - 1)
                           'populate dropdownlists
                           ddlChosenDate.Items.Add(CStr(FormatDateTime(dtDate, DateFormat.ShortDate)))
                           Exit For
                       End While
                   End If
               Next
           Next
       End If
   End Sub

Edited by Robby
Posted

if i set autopostback = true... then both my ddlChosenDate and ddlTimeSlots will get refreshed and set back to first item... that is:

"Select A time" or "Select A date"

 

I am trying to do an online booking by the way... i am looping to check if exact date and time has been booked.. if yes then wont add it to my dropdownlist for users to choose

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...