Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I think this forum rocks it has saved my bacon many many times..."

Geography

Where in the world do Tek-Tips members come from?
DENewkirk (Programmer)
20 Mar 08 12:05
I have 3 tables that I use temporarily to display search results in a DataGridView.  At the start of each search, I delete all of the rows and then save the search results.  For the first 2 tables, this process works entirely as expected, but for the 3rd table, the delete only works the first time in a session, leaving all rows in the table for subsequent searches.

Here is the code for one of the 2 successful routines:

CODE

    Private Sub SaveMaintenanceFileSearchResults()
        Dim Row As Integer = 0

        Dim strSQL As String = "SELECT Structure, DocumentDate, Category, ID FROM MaintenanceFileSearchResults ORDER BY Structure, DocumentDate"
        Dim Adapter As OleDb.OleDbDataAdapter = _
            DataLayer.GetDataAdapter(cMaintenanceManualsConnection, _
                                     strSQL)
        Dim MyTable As DataTable = _
            DataLayer.GetDataTable(Adapter, _
                                   cMaintenanceManualsConnection, _
                                   strSQL, _
                                   True)
        Dim Builder As OleDbCommandBuilder = New OleDbCommandBuilder(Adapter)

        Dim NewRow As DataRow

        With MyTable
            Adapter.DeleteCommand = Builder.GetDeleteCommand
            For Each NewRow In .Rows
                NewRow.Delete()
            Next NewRow
            Adapter.Update(MyTable)


            For Row = 0 To BDMDSSearchArrays.NumMaintenanceFiles
                NewRow = .NewRow
                NewRow.Item("Structure") = BDMDSSearchArrays.MaintenceFileResults(Row).StructureNo
                NewRow.Item("DocumentDate") = BDMDSSearchArrays.MaintenceFileResults(Row).DocumentDate
                NewRow.Item("Category") = BDMDSSearchArrays.MaintenceFileResults(Row).Category
                .Rows.Add(NewRow)
            Next Row

        End With

        With Adapter
            .InsertCommand = Builder.GetInsertCommand
            .UpdateCommand = Builder.GetUpdateCommand
            .Update(MyTable)
        End With

    End Sub

I adapted this code for the 3rd table, copying and pasting to make it as like as possible:

CODE

    Private Sub SaveCalcBookSearchResults()
        Dim Row As Integer = 0

        Dim strSQL As String = "SELECT CalcBook, ProjectName, Requester, Category, RequestYear, Structure, ID FROM CalcBookSearchResults"
        Dim Adapter As OleDb.OleDbDataAdapter = _
            DataLayer.GetDataAdapter(cMaintenanceManualsConnection, _
                                     strSQL)
        Dim MyTable As DataTable = _
            DataLayer.GetDataTable(Adapter, _
                                   cMaintenanceManualsConnection, _
                                   strSQL, _
                                   True)
        Dim Builder As OleDbCommandBuilder = New OleDbCommandBuilder(Adapter)

        Dim NewRow As DataRow

        With MyTable
            Adapter.DeleteCommand = Builder.GetDeleteCommand
            For Each NewRow In .Rows
                NewRow.Delete()
            Next NewRow
            Adapter.Update(MyTable)


            For Row = 0 To BDMDSSearchArrays.NumCalcBooks
                NewRow = .NewRow
                NewRow.Item("CalcBook") = BDMDSSearchArrays.CalcBookResults(Row).CalcBook
                NewRow.Item("ProjectName") = BDMDSSearchArrays.CalcBookResults(Row).ProjectName
                NewRow.Item("Requester") = BDMDSSearchArrays.CalcBookResults(Row).Requester
                NewRow.Item("Category") = BDMDSSearchArrays.CalcBookResults(Row).Category
                NewRow.Item("RequestYear") = BDMDSSearchArrays.CalcBookResults(Row).RequestYear
                NewRow.Item("Structure") = BDMDSSearchArrays.CalcBookResults(Row).StructureNo
                .Rows.Add(NewRow)
            Next Row

        End With

        With Adapter
            .InsertCommand = Builder.GetInsertCommand
            .UpdateCommand = Builder.GetUpdateCommand
            .Update(MyTable)
        End With

    End Sub

Both tables were created in the same manner (Design View) in the same Access database.  I'm scratching my head a bit here, needless to say.
DENewkirk (Programmer)
20 Mar 08 14:03
Oops!  The whole thing was my fault--in copying code just before the 'offending' code, I cleared the wrong internal table, so I merely added each new search's results to the old one.

As they used to say on Laugh-In, "Never mind!"
BobRodes (Instructor)
20 Mar 08 16:29
FYI, there is some confusion about this forum.  It got named before .Net was around, and is intended for issues surrounding database access with VB6.  If you have future issues with .Net code, you'll want to post them in the VB.Net forum.  smile

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close