Results 1 to 2 of 2

Thread: How do I requery an access database?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    63

    How do I requery an access database?

    Ok I am new to ADO.net 2.0 I've gotten a book and it has just too much information and is primarily for SQL Server. I am working with an access database. Here is how I am loading my form.

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

    'Get the current User on the machine
    strUserID = Mid(GetTheUserName(), 2)

    'Create the connection string to open the database
    m_cnADONetConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = F:\VBAStuff\VB 2005\Database Example\NewPride.mdb"

    'Open the the database and establish a connection to it.
    m_cnADONetConnection.Open()

    'Initialize the DataAdapter
    m_daDataAdapter = New OleDb.OleDbDataAdapter("Select ID, FirstName From Employee_Roster where [Reports To ID#] = '" & strUserID & "'", m_cnADONetConnection)

    'Initialize the Commandbuilder object
    m_cbCommandBuilder = New OleDb.OleDbCommandBuilder(m_daDataAdapter)

    'Fill the DataTable with the data from the table
    m_daDataAdapter.Fill(m_dtEmployee_Roster)

    Me.ShowCurrentRecord()

    End Sub

    Basicly what I am wanting to do is change the select statement and then requery the database and refill the dataAdapter but do not know how to do this.

    thanks for all you assistance.

    Mythos

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How do I requery an access database?

    First to your terminology. You don't fill or refill a DataAdapter. It's the DataAdapter that does the filling and the Datatable that gets filled. As to your question, I'm not going to answer without a bit more info. You say that you want to change the query but the CommandBuilder is based on the query so changing it is not advisable. What dod you want to change it to? Is it just to use a different user ID? If so then there's no need to change the query. You just add a parameter to the query and then change its value.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width