CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2007
    Posts
    84

    dataset question

    hi,

    my script is working fine, i have a button that executes a query and fill my dataset.
    but when i click again the button and execute the query it is just adding it to my dataset.
    i need to reset the dataset when i click the button, because it is a new query.

    Code:
     Private Sub bttnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnStart.Click
            Dim conn As New OleDbConnection()
            conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\ApplicationKit.accdb"
    
            Dim MyVariable As String
            Dim ChosenBttn As String
            Dim Vowel As String
            Dim Table As String
    
            Table = "Word"
            Vowel = "Word"
            MyVariable = cbPhonemes.SelectedIndex
            MyVariable = MyVariable + 1
            If bttnInitial.Checked = True Then
                ChosenBttn = "Initial"
            End If
            If bttnMedial.Checked = True Then
                ChosenBttn = "Medial"
            End If
            If bttnFinal.Checked = True Then
                ChosenBttn = "Final"
            End If
    
            Dim strSQL As String = "SELECT word, meaning FROM word WHERE (ID = " & MyVariable & ") AND ( [Position] = '" & ChosenBttn & "')"
            Dim da As New OleDbDataAdapter(strSQL, conn)
    
            da.Fill(ds)
    
            If ds.Tables(0).Rows.Count > 0 Then 'Check to see if the table is empty
                lblWord.Text = ds.Tables(0).Rows(0).Item("Word").ToString()
            End If
    
        End Sub

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: dataset question

    as ds is not local to the procedure, it never "die" and fill method called that way adds to it, do not substitute or refresh.
    If you need it alive, you have a couple of options:
    1)before filling it again, call
    ds.Tables.Clear()
    2)or use an overload of the fill method of OledbDataAdapter:
    Table="word"
    ...
    da.Fill(Ds, Table)


    see:
    http://msdn.microsoft.com/en-us/library/y4b211hz.aspx
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Oct 2007
    Posts
    84

    Re: dataset question

    thank you very much, it works like a charm...

  4. #4
    Join Date
    Jan 2010
    Posts
    38

    Re: dataset question

    Quote Originally Posted by homer.favenir
    thank you very much, it works like a charm...
    Yeah, Cimperiali rocks!
    Last edited by ddclondon; February 19th, 2010 at 05:28 AM.

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

Featured