Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. page index changed accessing dataadapter

page index changed accessing dataadapter

Scheduled Pinned Locked Moved ASP.NET
databasetutorialquestion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cavall
    wrote on last edited by
    #1

    I have a data adapter I create in another procedure and I am trying to access that specific data adapter in the page_index_changed event for the datagrid on the page, but I am unaware how to gain access to that adapter and dataset... Got any ideas? Thanks "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

    M 1 Reply Last reply
    0
    • C cavall

      I have a data adapter I create in another procedure and I am trying to access that specific data adapter in the page_index_changed event for the datagrid on the page, but I am unaware how to gain access to that adapter and dataset... Got any ideas? Thanks "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

      M Offline
      M Offline
      Marcie Jones
      wrote on last edited by
      #2

      If you didn't make it public in that other procedure, or save it off somewhere, then you'll need to recreate the DataAdapter/DataSet in the PageIndexChanged event. Marcie CP Blog[^]

      C 1 Reply Last reply
      0
      • M Marcie Jones

        If you didn't make it public in that other procedure, or save it off somewhere, then you'll need to recreate the DataAdapter/DataSet in the PageIndexChanged event. Marcie CP Blog[^]

        C Offline
        C Offline
        cavall
        wrote on last edited by
        #3

        so if I make that adapter public above... then how would I define the select command and connection in the other procedures? public da2 as new oledbdataadapter would the select be like this: da2.selectcommand.commandtext = "whatever" ?? that is my best guess there but I dont know about the connection... Thank you!!! "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

        C M 2 Replies Last reply
        0
        • C cavall

          so if I make that adapter public above... then how would I define the select command and connection in the other procedures? public da2 as new oledbdataadapter would the select be like this: da2.selectcommand.commandtext = "whatever" ?? that is my best guess there but I dont know about the connection... Thank you!!! "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

          C Offline
          C Offline
          cavall
          wrote on last edited by
          #4

          oh... duh... would connetion be da2.selectcommand.connection = strConn Thanks "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

          1 Reply Last reply
          0
          • C cavall

            so if I make that adapter public above... then how would I define the select command and connection in the other procedures? public da2 as new oledbdataadapter would the select be like this: da2.selectcommand.commandtext = "whatever" ?? that is my best guess there but I dont know about the connection... Thank you!!! "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

            M Offline
            M Offline
            Marcie Jones
            wrote on last edited by
            #5

            Even better, encapsulate all the logic that creates the Connection and the DataAdapter into one method, and call that method from both places. Marcie CP Blog[^]

            C 2 Replies Last reply
            0
            • M Marcie Jones

              Even better, encapsulate all the logic that creates the Connection and the DataAdapter into one method, and call that method from both places. Marcie CP Blog[^]

              C Offline
              C Offline
              cavall
              wrote on last edited by
              #6

              Marcie, I tried to make those guys public and work with them so I can throw some stuff together (I will encapsulate later) and i am getting this error: System.NullReferenceException: Object reference not set to an instance of an object Here is code: Imports System.Data.OleDb Public Class vqmResults1 Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Protected WithEvents Label1 As System.Web.UI.WebControls.Label Protected WithEvents Label2 As System.Web.UI.WebControls.Label Protected WithEvents Label3 As System.Web.UI.WebControls.Label Protected WithEvents Label4 As System.Web.UI.WebControls.Label Protected WithEvents lblOtherStartDate As System.Web.UI.WebControls.Label Protected WithEvents Label5 As System.Web.UI.WebControls.Label Protected WithEvents lblOtherEndDate As System.Web.UI.WebControls.Label Protected WithEvents txtOtherOpCode As System.Web.UI.WebControls.TextBox Protected WithEvents txtOtherVendor As System.Web.UI.WebControls.TextBox Protected WithEvents btnGetData As System.Web.UI.WebControls.Button Protected WithEvents dg As System.Web.UI.WebControls.DataGrid Protected WithEvents Label6 As System.Web.UI.WebControls.Label Protected WithEvents txtOpCode2 As System.Web.UI.WebControls.TextBox '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 Public da As New OleDbDataAdapter Public ds As New DataSet Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim OpCode As String Dim Vendor As String Dim StartDate As String Dim EndDate As String If Not Page.IsPostBack Then If Request.QueryString("oc") <> "" And Request.QueryString("vnd") <> "" And Request.QueryString("sdate") <> "" And Request.QueryString("edate") <> "" Then txtOtherOpCode.Text(

              1 Reply Last reply
              0
              • M Marcie Jones

                Even better, encapsulate all the logic that creates the Connection and the DataAdapter into one method, and call that method from both places. Marcie CP Blog[^]

                C Offline
                C Offline
                cavall
                wrote on last edited by
                #7

                Marcie, Have a little trouble creating a function to make the connection and configure adapter.. Can you help me out, please? Forgive me, Im a newbie... Public Sub MakeConnection(ByVal sqlSelect As String) Dim strConn As New OleDbConnection("Provider=""MSDAORA.1"";User ID=whatever;Data Source=VQM;Password=whatever") Dim da As New OleDbDataAdapter(sqlSelect, strConn) 'Dim ds As New DataSet strConn.Open() da.Fill(ds, "VENDORDESC") strConn.Close() End Sub My logic was going to be to take in a string as a parameter that would be the sql statment. Then I would populate the public dataset. Then in the Page_Index_Changed (for example) I would call MakeConnection(whatever), which would populate that dataset and then I would bind the datagrid. I could be way off here... If I am not way off... why does the Page_Load and other methods/events in the class not recognize the MakeConnection function as being defined? Also, aside from making the sqlSelect a public variable... how would I use that as to be able to have the Page_Load logic create the sql string and have it also used in the Page_Index_Changed event? Thanks for the help!! cavall "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups