locked
AccessdataSource isnt declared RRS feed

  • Question

  • User666269472 posted

    Imports System.Data
    Partial Class AddCustomer
        Inherits System.Web.UI.Page
        Dim dv As New DataView
        Dim drv As DataRowView
        Dim TotalRecords As Integer
        Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            dv = adsMembers.Select(DataSourceSelectArguments.Empty)
            TotalRecords = dv.Count
            adsMembers.DataBind()
            If Not Page.IsPostBack Then
                Session("Position") = 0
                drv = dv(CInt(Session("Position")))
                displayRecord()
            End If
            lblTotal.Text = TotalRecords.ToString
            HideTextBoxes()
            DisableValidators()
            ShowNavigationButtons()
            ShowUpdateButtons()
            btnSavMem.Visible = False
            btnUpdate.Visible = False
        End Sub

    Private Sub btnNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewMem.Click
            HideNavigationButtons()
            HideUpdateButtons()
            btnSavMem.Visible = True
            ClearTextBoxes()
            ShowTextBoxes()
            HideLabels()
            EnableValidators()
        End Sub
        Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSavMem.Click
            adsCustomers.Insert()
            dv = adsCustomers.Select(DataSourceSelectArguments.Empty)
            TotalRecords = dv.Count
            adsCustomers.DataBind()
            Session("Position") = dv.Count - 1
            drv = dv(CInt(Session("Position")))
            displayRecord()
            HideTextBoxes()
            ShowLabels()
            DisableValidators()
            ShowNavigationButtons()
            ShowUpdateButtons()
            btnUpdate.Visible = False
            btnSave.Visible = False
        End Sub
        Private Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
            If CInt(Session("Position")) + 1 < TotalRecords Then
                Session("Position") = CInt(Session("Position")) + 1
                lblRecNum.Text = CStr(CInt(Session("Position")) + 1)
                drv = dv(CInt(Session("Position")))
                displayRecord()
            End If
            ShowNavigationButtons()
            ShowUpdateButtons()
            btnUpdate.Visible = False
            btnSavMem.Visible = False
        End Sub
        Private Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrevMem.Click
            If Session("Position") <> 0 Then
                Session("Position") = CInt(Session("Position")) - 1
                lblRecNum.Text = CStr(CInt(Session("Position")) + 1)
            End If
            If CInt(Session("Position")) < 0 Then
                Session("Position") = 0
                lblRecNum.Text = CStr(CInt(Session("Position")) + 1)
            Else
                drv = dv(CInt(Session("Position")))
                displayRecord()
            End If
            ShowNavigationButtons()
            ShowUpdateButtons()
            btnSavMem.Visible = False
            btnUpdate.Visible = False
        End Sub
        Private Sub btnEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEdit.Click
            ShowTextBoxes()
            HideLabels()
            lblMemID.Visible = True
            EnableValidators()
            rfvCustID.Enabled = False
            cpvCustID.Enabled = False
            drv = dv(CInt(Session("Position")))
            lblCustID.Text = drv("CustomerID").ToString
            txtCustID.Visible = False
            txtFirstname.Text = drv("FirstName").ToString
            txtSurname.Text = drv("Surname").ToString
            txtPhone.Text = drv("Phone").ToString
            txtPostCode.Text = drv("PostCode").ToString
            txtTown.Text = drv("Town").ToString
            HideNavigationButtons()
            HideUpdateButtons()
            btnUpdate.Visible = True
        End Sub
        Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles btnUpdate.Click
            adsCustomers.ConflictDetection = ConflictOptions.OverwriteChanges
            adsCustomers.Update()
            dv = adsCustomers.Select(DataSourceSelectArguments.Empty)
            TotalRecords = dv.Count
            adsCustomers.DataBind()
            drv = dv(CInt(Session("Position")))
            displayRecord()
            HideTextBoxes()
            ShowLabels()
            ShowNavigationButtons()
            ShowUpdateButtons()
            btnUpdate.Visible = False
            btnSave.Visible = False
            DisableValidators()
        End Sub
        Private Sub btnFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFirst.Click
            lblWarning.Text = ""
            Session("Position") = 0
            lblRecNum.Text = CStr(CInt(Session("Position")) + 1)
            If CInt(Session("Position")) >= TotalRecords Then
                Session("Position") = CInt(Session("Position")) - 1
            Else
                drv = dv(CInt(Session("Position")))
                displayRecord()
            End If
            ShowNavigationButtons()
            ShowUpdateButtons()
            btnSave.Visible = False
            btnUpdate.Visible = False
        End Sub
        Private Sub btnLast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLast.Click
            TotalRecords = dv.Count
            Session("Position") = TotalRecords - 1
            lblRecNum.Text = CStr(CInt(Session("Position")) + 1)
            If CInt(Session("Position")) >= TotalRecords Then
                Session("Position") = CInt(Session("Position")) - 1
            Else
                drv = dv(CInt(Session("Position")))
                displayRecord()
            End If
            ShowNavigationButtons()
            ShowUpdateButtons()
            btnSave.Visible = False
            btnUpdate.Visible = False
        End Sub
        Private Sub btnLast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLast.Click
            TotalRecords = dv.Count
            Session("Position") = TotalRecords - 1
            lblRecNum.Text = CStr(CInt(Session("Position")) + 1)
            If CInt(Session("Position")) >= TotalRecords Then
                Session("Position") = CInt(Session("Position")) - 1
            Else
                drv = dv(CInt(Session("Position")))
                displayRecord()
            End If
            ShowNavigationButtons()
            ShowUpdateButtons()
            btnSave.Visible = False
            btnUpdate.Visible = False
        End Sub
        Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
            adsCustomers.ConflictDetection = ConflictOptions.OverwriteChanges
            Try
                adsCustomers.Delete()
                dv = adsCustomers.Select(DataSourceSelectArguments.Empty)
                TotalRecords = dv.Count
                adsCustomers.DataBind()
                If Session("Position") <> 0 Then
                    Session("Position") = CInt(Session("Position")) - 1
                End If
                drv = dv(CInt(Session("Position")))
                displayRecord()
                ShowLabels()
            Catch ex As Exception
                lblWarning.Text = " This record has related entries -"Deletion aborted"
            End Try
        End Sub
        Private Sub displayRecord()
            lblCustID.Text = drv("CustomerID").ToString
            lblFirstName.Text = drv("FirstName").ToString
            lblSurname.Text = drv("Surname").ToString
            lblPhone.Text = drv("Phone").ToString
            lblPostCode.Text = drv("PostCode").ToString
            lblTown.Text = drv("Town").ToString
            lblTotal.Text = CType(TotalRecords, String)
            lblRecNum.Text = CType(CInt(Session("Position")) + 1, String)
        End Sub
        Private Sub DisableValidators()
            rfvCustID.Enabled = False
            rfvSurname.Enabled = False
            rfvFirstname.Enabled = False
            rfvPhone.Enabled = False
            rfvTown.Enabled = False
            rfvPostcode.Enabled = False
        End Sub
        Private Sub EnableValidators()
            rfvCustID.Enabled = True
            rfvSurname.Enabled = True
            rfvFirstname.Enabled = True
            rfvPhone.Enabled = True
            rfvTown.Enabled = True
            rfvPostcode.Enabled = True
            revPostcode.Enabled = True
            cpvCustID.Enabled = True
        End Sub
        Private Sub HideLabels()
            lblCustID.Visible = False
            lblFirstName.Visible = False
            lblSurname.Visible = False
            lblPhone.Visible = False
            lblPostCode.Visible = False
            lblTown.Visible = False
        End Sub
        Private Sub ShowLabels()
            lblCustID.Visible = True
            lblFirstName.Visible = True
            lblSurname.Visible = True
            lblPhone.Visible = True
            lblPostCode.Visible = True
            lblTown.Visible = True
        End Sub
        Private Sub HideTextBoxes()
            txtCustID.Visible = False
            txtFirstname.Visible = False
            txtSurname.Visible = False
            txtPhone.Visible = False
            txtTown.Visible = False
            txtPostCode.Visible = False
        End Sub
        Private Sub ShowTextBoxes()
            txtCustID.Visible = True
            txtFirstname.Visible = True
            txtSurname.Visible = True
            txtPhone.Visible = True
            txtTown.Visible = True
            txtPostCode.Visible = True
        End Sub
        Private Sub ClearTextBoxes()
            txtCustID.Text = ""
            txtFirstname.Text = ""
            txtSurname.Text = ""
            txtPhone.Text = ""
            txtTown.Text = ""
            txtPostCode.Text = ""
        End Sub
        Private Sub ShowNavigationButtons()
            btnFirst.Visible = True
            btnLast.Visible = True
            btnNext.Visible = True
            btnPrevious.Visible = True
        End Sub
        Private Sub HideNavigationButtons()
            btnFirst.Visible = False
            btnLast.Visible = False
            btnNext.Visible = False
            btnPrevious.Visible = False
        End Sub
        Private Sub ShowUpdateButtons()
            btnNew.Visible = True
            btnEdit.Visible = True
            btnSave.Visible = True
            btnUpdate.Visible = True
            btnDelete.Visible = True
        End Sub
        Private Sub HideUpdateButtons()
            btnNew.Visible = False
            btnEdit.Visible = False
            btnSave.Visible = False
            btnUpdate.Visible = False
            btnDelete.Visible = False
        End Sub
    End Class

    The code above I have inserted in to the code "behind page" of a form. Now I have created an accessdatasource called "adsMembers" on the design page which connects to the database no problem but when I go to insert the above named "accessdatasource" in to the above code it keeps saying that "adsMembers is not declared". Have racked by brain for hours trying to get this. The Label and Button and Regular Field Validators ids arent "being declared" either.    Any and all help will be greatly appreciated

    Wednesday, May 23, 2012 5:54 AM

Answers

  • User666269472 posted

    I wanna thank you for the time you took to answer my post. I finally figured out what was wrong. "Partial Class" AddCustomer" at the top of the page should have been "Partial Class""ShiftAGear".

    Thanks anyway...much appreciated.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 23, 2012 1:44 PM

All replies

  • User-718146471 posted

    To access the frontside controls you have to do a FindControl in the code behind. For the datasource, you do something like this (example if you wanted to count the number of results in the datasource):

    Dim dvSql1 As DataView = DirectCast(dsApprovedTraining.[Select](DataSourceSelectArguments.Empty), DataView)
    Dim val1 As Integer = Convert.ToInt32(dvSql1.Count.ToString())
    

    To do a find on a textbox and a button control for example, you do this:

    Dim TextBox1 As TextBox = DirectCast(FindControl("TextBox1"), TextBox
    Dim Button1 As Button = DirectCast(FindControl("Button1"), Button))

    Once you've performed this findcontrol, your control will be available to your code behind. If it is a child of another control, you have to call out the parent control name and tehn do FindControl like  

    Dim TextBox1 As TextBox = DirectCast(FormView1.FindControl("TextBox1"), TextBox)
    Wednesday, May 23, 2012 8:58 AM
  • User666269472 posted

    I wanna thank you for the time you took to answer my post. I finally figured out what was wrong. "Partial Class" AddCustomer" at the top of the page should have been "Partial Class""ShiftAGear".

    Thanks anyway...much appreciated.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 23, 2012 1:44 PM